For far too many times have I heard that question and far too many times have I heard someone saying that it’s not a popular combination or questioning this choice. It’s time to finally release my frustration and dispel any doubts on this topic.
Here’s what we are going to cover in this article:
- Why MySQL may look unnatural for Node?
- What database should you choose when working with Node?
- Can I use MySQL with Node?
The aim of this article is to explain the common misconception about using MySQL with Node.js and to assure you that there is completely nothing wrong with using this database together with Node.js. Let’s get started.
I think the whole uncertainty of choosing MySQL for Node.js projects comes from the conviction that when you are using Node and want to store your data in a database then you should pick MongoDB. Why is that? Well, I think we need to get back in time to 2013 when the acronym MEAN was coined.
- MEAN – the original stack with Angular as the main frontend technology
- MERN – a variation using React as the frontend technology
- MEVN – a variation using Vue as the frontend technology
Today, the MERN stack became even more popular than the original variation because React's popularity is skyrocketing.
All of this caused that today these stacks seem to be a natural combination for Node. This belief becomes stronger as new developers learn that it’s the only right way of building JS apps and share it further. MongoDB became a default choice for Node apps – especially for junior developers or people who are completely new to programming. Of course, this is wrong.
So what is the best option for Node? What should be your default choice when choosing a database for Node? Let’s find out.
Let’s start with the fact that there is no such thing as a default database for any technology. That’s not how it works. You never should pick a database based on the technology that you use in your application. The reason is that similarly to the choice of backend and frontend technology it all depends on requirements. The project requirements should be your main deciding factor for database technology. On top of that, when your architecture is well-designed the kind of your database becomes a technical detail that does not have anything in common with programming languages used to create a backend.
Every database available on the market has its own advantages and will be the best choice for projects that it has been created for. Taking only the two databases that we are discussing here – MySQL and MongoDB – each of them should (and should not) be used in certain scenarios. If in your project you must deal with a large amount of data (like really large) or the data is unstructured or it has a potential for rapid growth then probably the better choice is to use MongoDB. On the other hand, if you have structured data or your priority is data security or you just need a relational database then MySQL is a lot better choice.
So let me repeat that again: there is no default database for any backend technology. It all depends on project requirements and what do you expect from the database. You should never be guided by the technology that you chose to create your backend.
Having said that, let’s finally answer the main question of this article.
Yes! There is completely nothing wrong with that. I hope you realize this by now. The common misconception comes from the huge popularity of the
At the end of the day, we do have ORMs like TypeORM or Sequelize (or a dozen of others) that support MySQL drivers and they are very popular – it also means something.
To sum up, the most important thing to realize is that there is no such thing as a default database for Node.js (or any technology) and that you never should pick MongoDB just because you use Node. In fact, Node.js does not care about data storage really – just like Java or Python, Node.js is a backend technology used to implement server-side business logic. You should always choose the database that meets your particular project needs regardless of the chosen programming language.
With that in mind, go ahead and create a new Node.js project without worrying if MySQL will be a good choice.