Node.js Request Module
The request module is used to make HTTP calls. It is the simplest way of making HTTP calls in node.js using this request module. It follows redirects by default.
Feature of Request module:
- It is easy to get started and easy to use.
- It is widely used and popular module for making HTTP calls.
Installation of request module:
- You can visit the link Install Request module. You can install this package by using this command.
npm install request
- After installing request module you can check your request version in command prompt using the command.
npm version request
- After that, you can create a folder and add a file for example index.js, To run this file you need to run the following command.
node index.js
Filename: index.js
const request = require( 'request' ) // Request URL request(url, (error, response, body)=>{ // Printing the error if occurred if (error) console.log(error) // Printing status code console.log(response.statusCode); // Printing body console.log(body); }); |
Steps to run the program:
- The project structure will look like this:
- Make sure you have install express and request module using following commands:
npm install request
npm install express
- Run index.js file using below command:
node index.js
So this is how you can use the request module for making HTTP calls. It is very simple and easy to use.