Hey folks! I would like to ask you a question. What is the main thing of an application ? Well, just as you thought, it can be anything. Actually the goal of an application defines that thing. Therefore I will ask you a more specific question. What is the main thing of an application, if it’s built to do heavy CRUD operations?

In this case, database is the main thing of that application. I got you there, right? Most applications, microservices, cronjobs etc. do CRUD operations in their lifecycles. I work as full stack software engineer in Istanbul and wrote tons of CRUD operations. Finally, I found a proper way to connect MongoDb in NodeJs (with Mongoose of course.). Before we dive deep into this, we need couple of things to do.

What do we need?

As the title said, we need

  • NodeJs LTS — 10^
  • MongoDb
  • Docker
  • Visual Studio Code (with beloved Lexcuim Black theme)

I guess these are the needs for now. Let’s use them to do what we came to do.

Getting Ready To Start

First thing first, we need to install NodeJs. Open this link in another tab to download LTS version of NodeJs.Then we need to prepare MongoDb. Therefore we need to install Docker on our machines, because it is the easy way to manage MongoDb. Open this link to download Docker and run the code placed below after installation is done.

docker run -d  --name mongoDb  -p 27888:27017 mongo

If you do not want to install Docker, we can simply use MongoDb Atlas. Open this link to create an account.

#mongoose #mongodb #nodejs

How to Connect Node.js with MongoDB
5.60 GEEK