Connect Mongodb Atlas to nodejs and Express Server



Connect Mongodb Atlas to nodejs and Express Server

Connect Mongodb Atlas to nodejs and Express Server

Learn how to connect Mongodb Atlas to a Node Express backend.

We will be doing everything from scratch, making our free cluster and database in the cloud. Then we configure database access and make a user to access it. The way we connect with Mongodb Atlas is through a connection string, that we store in a .env file locally in our backend project.

When that is done we make our node express server with two endpoints. One GET route for getting all the entities (customers) and creating a new one though a POST endpoint. Inside our project we also make a schema of the customer object we will be working with.

To query our backend we use Postman, which is a very useful tool for this, and you can download it here:
https://www.postman.com/downloads/ 💌

Timecodes
0:00​ – Intro
0:30 – creating cluster
1:24 – creating user
02:30 – creating database
03:50 – Network access
04:45 – connection string
08:00 – environmental file
11:10 – app.js file
15:15 – mongoose
18:48 – customer schema
23:38 – POST endpoint
28:37 – POST in Postman
31:35 – GET endpoint
33:30 – Complete

Complete code on Github:
https://github.com/Polkagris/connect_mongodbatlas_nodejs 🐱

How to get the code without using the terminal:
1. Go to the Github link
2. Click on the green Code-button
3. Click Download ZIP
4. Extract and open the folder in your preferred code editor (I’m using visual studio code, download link below)
5. To see the game in action, just open the index.html file in you browser

Read my blog on Dev.to – https://dev.to/redeyemedia 🧐

New videos every week!

Comments are closed.