loading...

Which is the Best Database for NodeJS?

oyetoket profile image Oyetoke Toby ・1 min read

Which of the below is your preferred database for Node:

  • MySQL
  • PostgreSQL
  • MongoDB
  • SQLite

Discussion

pic
Editor guide
 

The database you choose will depends on your project needs. If I need strict relations in my data I do not use MongoDB. In such cases, SQLite usually serves my purpose for POCs and in prod I like PostgresSQL. I love using Sequelize ORM docs.sequelizejs.com/ which supports MySQL/PostgreSQL/SQLite. For apps that involves file storage I use MongoDB.

 

+1 for sequelize

 

+1 for Sequelize!

 

I'm partial to Postgres in general but the most important considerations are really your data model and other requirements, not what you're running. If your data model is hierarchical with few relationships (unusual, but it happens) MongoDB is built for that. If your project is small-scale enough that you're okay with the database living on the same filesystem and having only one active connection at a time, SQLite will do perfectly well, although if you've already got Postgres running there's no reason not to use that either.

 
  • SQLite for when I'm doing a very quick PoC.
  • MongoDB for when I'm trying to get that PoC to production quickly, and just needs a basic data store.
  • PostgreSQL when I need a powerful database in production and I'm not necessarily in a sprint to the end.
 

This is such an incredibly broad question.

The choice of database should not be decided because it's someones "preferred" technology.

What's the best database for the project you're working on - that's the question you should be asking.

That's the question you should be asking of every technology you use. Is Node even the right language for the job you're trying to do?

 

MongoDB is what I'm using for almost anything if I have the power to choose. Because as a frontend developer I really don't want to spend too much time on creating subtle data model schemes for lightweight projects. But we use a lot postgres in the real production.

 

hasura graphql on top of postgres has been working wonders for me lately!