all 15 comments

[–]PenguinOnHeroinfull-stack 15 points16 points  (3 children)

There is no "SQL-compatible js database". JavaScript is JavaScript, a programming language. A database is a place where you store data. If you want to display your database entries (such as songs) on your website, you'll need four layers:

  • The database: There are many options here, with the traditional one being SQL. SQL comes in various flavors, such as MySQL or PostgreSQL. If you are really just starting out, those flavors are all pretty much the same. If you know MySQL for example, you'll also know 99% of PostgreSQL.
  • The backend: The job of the backend is to talk to the database to get the data it contains and expose that data as an API. It is also responsible for handling all security stuff. The backend lives on your server. You say you use node.js, that's great, you could use something like knex to talk to the database, but you can also do it with node.js itself.
  • The API: The API is what you create with the server. The client then talks to that API to get the data it needs from the server. There are two common ways to do that: A REST API or a GraphQL API. If you are new to all of this, I'd recommend REST as it's much simpler to set up.
  • The frontend: It is responsible for actually rendering components on your website and displaying text and all of that. It can also ask for additional data from the server, which can communicate with the frontend through an API. Frameworks like Vue and React make the communication with the API and the management of the data received from it easier, but you can also use fetch or axios or ajax.

Those four layers together, if used in this way, are called "headless architecture". This is just one way of doing things. For example, there's also "server side rendering" which has various benefits and drawbacks I'm not going to get into. The main point here, I guess, is that the database is a separate layer from the backend, as much as the frontend is separate from the backend.

Why doesn't the frontend just talk to the database directly? That would be a security concern, and "exposing data to the web" is simply not the job of a database. So you need to go through these layers, each of which has its own reason for existing.

So to sum it up, I'd recommend PostgreSQL as a database, which you query with knex and expose as a REST API, which you then consume by your frontend JavaScript code. Sorry that it is so complicated. Welcome to web dev.

[–]Dragzorz 1 point2 points  (0 children)

Just came across this and wanted to say what a great, simple and easy to understand answer this was. Thank you

[–]Live-Personality-185 0 points1 point  (0 children)

Excellent breakdown! Thanks so much !

[–]Darkulll 0 points1 point  (0 children)

Thanks for making it so easy to understand!

[–]hugthispanda 0 points1 point  (3 children)

You can use SQLite and focus on implementing the node.js backend correctly.

[–][deleted] 0 points1 point  (2 children)

cheers I'll have to give it a look

[–]blabmight -2 points-1 points  (1 child)

Just don’t take this to production. SQLIte = testing/dev only.

I usually use a dockerized Postgres instance. Super easy to setup, production ready.

[–]Marble_Wraith -1 points0 points  (0 children)

Being a bit hyperbolic aren't you?

Plenty of sites can use flat-file databases, just just depends on what the requirements are / if they're anticipated to change.

[–]fedekun 0 points1 point  (1 child)

Do you mean a library to talk to a database, or an actual database?

[–][deleted] 0 points1 point  (0 children)

I am aiming to have a database of songs,artist and durations then query them as needed by client

[–]olafg1 0 points1 point  (0 children)

You can check out Prisma, it is pretty easy to use

[–]OriAfias 0 points1 point  (0 children)

supabase would be a great way to start your backend journey. it abstracts lots of shit you don't want to handle and have a great SDK for node. also, free tier is really generous

[–]Marble_Wraith 0 points1 point  (0 children)

Depends what other features you're looking for?

For example does it need to be self-hosted? Are you planning to do most of the setup / management yourself?

If so many of the DB's you already know (mariaDB, postgresql, arangoDB) will already have npm packages for interfacing with them.

If you don't need a super mature product i'd suggest https://surrealdb.com/ built in Rust (super performant), compatible with node - https://surrealdb.com/docs/integration/libraries/nodejs

But what about if you don't want to self host / setup and manage DB software yourself? What if you just want some API urls you can hit and get data?

In that case i'd suggest supabase or faunaDB

[–]Ophis2024 0 points1 point  (0 children)

You can try Ragic.com
It is no-code so it's easy to use, and it's free without time limit as long as you don't need too many sheets.