How to Create Basic API in Node JS Express?

By Hardik Savani September 28, 2021 Category : Node JS


Now, let's see article of how to create api in node js. We will look at example of how to create api in node js express. you can understand a concept of node js create api example. if you have question about create simple api using node js then i will give simple example with solution.

Here, i will give you very simple example how to create simple api in node js with express. we will create "users" api and return users.json file data. so let's follow bellow step to create simple example

Step 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Install Express using bellow command:

npm install express --save

Step 2: Create server.js file

Here, we will create simple users api with GET method.


const express = require('express')

const fs = require('fs')

const app = express()

app.get('/', (req, res) => {

res.end('Hello World!, Example from');


app.get("/users", (req, res) => {

fs.readFile(__dirname + '/' + 'users.json', 'utf8', (err, data) => {




app.listen(3000, () => {

console.log(`app listening at //localhost:3000`)


Now let's create users.json file as bellow:




"id": 1,

"name": "Hardik",

"email": ""



"id": 2,

"name": "Vimal",

"email": ""



"id": 3,

"name": "Harshad",

"email": ""



now you can simply run by following command:

node server.js


i hope it can help you...

Tags :