Setting Up Node JS API- Rest API for My Articles In 8 Steps

Srikanth
4 min readAug 26, 2023

--

Hi Everyone!!!, I hope you are doing well, stay safe and healthy. Thanks for clicking on this article.

Photo by Gabriel Heinzer on Unsplash

Apologies for delay in posting this article.

This article will help you to set up node js api in local machine. By using this api, you can work with frontend and integration with apis easily.

Also, you can use this api to work with my past and upcoming articles, most of my articles am using same api.

Please set up mongodb atlas(MongoDB Compass) in your local machine before setting up node js api. Click on below link to go to mongo dB atlas setup article.

Set up mongo dB online using mongo dB atlas and Import data in 25 Steps. | by Srikanth | Aug 2023 | Medium

Step 0. Once mongo DB atlas setup is done, then you can come to this article and do setup for node js api.

This article is only for setting up the node js api, meaning not teaching the node js code, just cloning my node js project, run and set up. Will show apis list and how apis work.

Note #1: Please copy the mongo dB connection string and keep it with you, I will tell you which file we need to paste that URL.

What is Node JS?

Node JS is a backend server and an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser.

Node.js is a popular, lightweight web framework, and it is used by many companies. Initially, JavaScript only used in server-side technologies like java, .NET to develop dynamic webpages. But nowadays we are writing JavaScript code inside node js server to deal with request and responses.

Before going to step 1, please install the node js in your local by using below link.

Download | Node.js (nodejs.org)

But my node js api supports version will be v14.15.0, Please download to avoid conflicts.

Index of /download/release/v14.15.0/ (nodejs.org)

You can work with new version also, but you need to change the versions of npm packages and some of the code inside the app.

Step 1: Once mongodb atlas and node js installation done, Clone or download my node js api source code by using below url.

mryenagandula/Letstalk-Backend: Its a blog related sample project containing all crud functionalities includes auditing. (github.com)

Click on Download ZIP button or copy clone URL. Am clicking on download zip button.

The file will be downloaded, extract the file and open the file by using vs code.

Step 2. Go to project directory, where you will see the package.json file. That location open command prompt and do npm install.

Step 3. Open project in vs code, the project structure will be look like below.

Step 4. Click on control + p and type index.js click enter to open the file.

After that, search for mongodb connection in code level,

Change process.env.MONGO_URI to mongodb atlas URI.

Sample URL looks like below.

mongodb+srv://mryenagandula:kt2bw56648OOMWBb@democluster0.gz8zvsw.mongodb.net/NodeJs5

Step 5: Once URI is updated, then do npm run dev in command prompt to run the node js api.

Step 6. Open node js api in chrome by using localhost:3000, You can see the list of public apis, you can access them without any token.

Step 7. click on public/users link, you can see the list of users data in json format and also you can integrate with this your frontend app.

Step 8. Up to now clear right, this way you can connect with my node js api with mongo dB atlas and use in frontend app.

Any issue found in node js api setup, please check it from the first step. If anything, miss in my article please write a mail or give me feedback on the comments section.

Happy Coding !!!,

Thanks for reading this article, This is Srikanth. Namaste !!!.

Please share your feedback, claps, and comments. In that way, it will have helped me to improve my articles in the future. Please share my story with your near and dear, also follow and subscribe to the medium

--

--

Srikanth

Senior Software Engineer | Medium Articles | Storyteller | Quick Learner | React JS | Angular | Java | Learn Something new from my stories