Open In App

How to get multiple requests with ExpressJS ?

Last Updated : 31 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Express.js is the most powerful framework of the node.js. Express.js is a routing and Middleware framework for handling the different routing of the webpage, and it works between the request and response cycle. Express.js use different kinds of middleware functions in order to complete the different requests made by the client for e.g. client can make get, put, post, and delete requests these requests can easily handle by these middleware functions

Working of the middleware functions:

Installing module: Install the express module using the following command.

npm install express

Project structure: Our project structure will look like this.

Handling Multiple requests using Express.js:

Express.js contains multiple methods to handle all types of requests rather than work on a single type of request as shown below:

  • Express.js req.get() Method: This method is used when get request is done by the client for e.g Redirecting another webpage requests etc
  • Express.js req.post() Method: This method is used when post requests are done by the client for e.g. uploading documents etc.
  • Express.js req.delete() Method: This method is used when a delete request is done by the client it is mainly done by the admin end for e.g. deleting the records from the server.
  • Express.js req.put() Method: This method is used when update requests are done by the client to update the information over the website.

index.js




// Requiring module 
const express = require("express"); 
  
// Creating express app object 
const app = express(); 
  
app.post("/check",(req,res,next)=>{
  res.send("This is the post request")
  next()
})
  
app.get("/gfg",(req,res,next)=>{
  res.send("This is the get request")
  res.end()
})
  
app.delete("/gfgdelete",(req,res,next)=>{
  res.send("This is the delete request");
  res.end()
})
  
// Server setup 
app.listen(3000, () => { 
  console.log("Server is Running"); 
})


Run index.js file using below command:

node index.js

Output:

Server is Running

Handling Multiple Requests: Now open the postman tool and send the following requests:

  • DELETE request from client:

  • GET request from client:


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads