5 STEPS TO CREATE REST API IN NODE JS | Node JS REST API

Hello and welcome, I'm going to tell you, how to create RESTful API with Node JS Express in 5 SIMPLE STEPS. "5 SIMPLE STEPS FOR CREATING REST API IN NODE JS EXPRESS".

Right, lets make a start:


TABLE OF CONTENT 00:00 Introduction
00:11 ENSURE NODE AND NPM INSTALLATIONS
00:45 PREPARE WORKSPACE
01:17 PROJECT INITIALIZATION
02:40 CREATE MAIN FILE
05:25 RUNNING LOCALLY
06:00 Thank you for listening

5 SIMPLE STEPS FOR CREATING REST API IN NODE JS EXPRESS STEP 1: ENSURE NODE AND NPM INSTALLATIONS Ensure you have node/npm installed by running

npm -v OR node -v
These commands gives the installed node and npm versions.

STEP 2: PREPARE WORKSPACE Make you workspace readt by simply creating the project folder by running

mkdir node-apicd node-api
In this video, I'm going to use commands only. If you want you can create the project folder using GUI.
STEP 3: PROJECT INITIALIZATION

Now, initialize npm project by running
npm init
It will ask for a bunch of information. If you don't want to provide the details right away just suffix [--yes OR --y] option
in npm init command. This created package.json file inside your workspace.
Now, we will install express by running
npm install express
This will install express locally for your project only.
STEP 4: CREATE MAIN FILE
Now, we will create index.js file. This file is also called the main OR entry file. This file imports required package for the project.
INDEX.JS FILE CODE:

// Import express dependency var express = require('express'); // Create a new express instance var app = express(); //Create routes app.get("/", function(req, res, next) { res.send("Hello world"); }); // Listern on 3000 port app.listen(3000, function() { console.log("Started on port: 3000");});
This app.listen method starts the application on port 3000 for all the connections. The app responds with "Hello world" for the requests to root url (/).
For every other paths/routes, it will respond with a 404 not found.
STEP 5: RUNNING LOCALLYAt last, run the app with

node index.js
Then load localhost:3000 in a browser to see the output.
Alright, now try to create express app from skretch and ask for thee problems in the comments.
Thank you for listening.


To Get Regular Content Updates, subscribe my youtube channel-

https://www.youtube.com/c/renurawat?sub_confirmation=1

Comments