Connect MongoDB to NodeJS Server

Connect MongoDB to NodeJS Server

Hello, people of Hive in this guide, we will keep learning how to use MongoDB and in this case we see how to connect the Database we created with our NodeJS server, if you don't know how to create a database check the last guide I posted where I created a new database from 0.

mongoconnect1.png

First, we go to the main Dashboard inside the MongoDB console, we already saw this in the last post, here we will click on the green connect button, if you have not created the database, it's really easy to go for the free deployment or check the last post. Also check the Network Configuration we made to allow 0.0.0.0/0 so we don't need to worry about IPs right now, just for testing this is not a problem for security, but for real deploys you need to check that.

mongo1.png

We will see these options and a lot more, select the first that says Drivers, and you can see it says that it's compatible with NodeJS and other Frameworks, also Compass is a great tool it's the Desktop Version of MongoDB but we don't need to download any software that's an advantage of using MongoDB console in the web, we can access like any cloud service.

mongo2.png

Now we see this info, here we need to select NodeJS and version as it shows in the picture, the install driver we can ignore because we will use Mongoose instead of Mongodb, we will see more in the next guides about the difference. And we need to copy this link we see in the third point, that's the link we will use in our NodeJS to connect to the Databse.

mongo3.png

Finally, we need to edit our NodeJS server.js as we see next, we need to change the link with the link we got from our mongoDB previous step, we also need to npm install, express, mongoose, and body-parser, we will see the server.js again in the next guide, but with this, we can start the express server and we connect to the database we created.

mongo4.png

In the next guides we will see how to interact with the database and we will complete with each step the NodeJS code, right now we have our database and server ready to start creating some Data and functions to interact with the server and Database.

You can check my blog here: https://peakd.com/@taradraz1

Thanks for the time!!!



0
0
0.000
2 comments
avatar

Congratulations @taradraz1! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 100 HP as payout for your posts, comments and curation.
Your next payout target is 250 HP.
The unit is Hive Power equivalent because post and comment rewards can be split into HP and HBD
You published more than 40 posts.
Your next target is to reach 50 posts.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

Thanks for including @stemsocial as a beneficiary, which gives you stronger support. 
 

0
0
0.000