Express js, Node js Rest API tutorial hindi 2024
In this tutorial, we will learn how to create a Rest API using Express js and Node js. Rest API is a way to communicate between the client and server using HTTP methods like GET, POST, PUT, DELETE, etc.
Here is a step-by-step guide to create a Rest API using Express js and Node js:
- First, you need to install Node.js on your system
- Next, create a new project folder and navigate to it in the terminal
- Run the command npm init to create a package.json file for your project
- Install Express js by running the command npm install express
- Create a new file app.js and start by importing Express js
Here is an example of a simple Express js server that listens on port 3000:
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Now, to create a Rest API, you can define different routes for different HTTP methods like GET, POST, PUT, DELETE, etc. Here is an example of a simple API endpoint that returns a list of users:
app.get('/users', (req, res) => {
res.json([
{ id: 1, name: 'John Doe' },
{ id: 2, name: 'Jane Smith' }
]);
});
That’s it! You have created a simple Rest API using Express js and Node js. You can now test your API using tools like Postman or curl.
For more advanced tutorials and tips on building Rest APIs using Express js and Node js, stay tuned for more updates.
Greate content for beginners. please make a video how we can fetch related data from different collection. I have completed all 7 videos.
Very nice
First viewer