The request module in Node is used to make HTTP requests. It allows developers to simply make HTTP requests like GET, POST, PUT, and DELETE in the Node app. It follows redirects by default.
Syntax:
const request = require('request');
request(url, (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log(body); // Handle the response body
}
});
Note: As of Feb 11th, 2020, the request is fully deprecated.
Features:
- It is easy to get started and easy to use.
- It is a widely used and popular module for making HTTP calls.
Steps to Install Request Module
You can visit the link Install Request module. You can install this package by using this command.
npm install request
After installing the request module you can check your request version in the 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
The project structure will look like this:

Example: This example uses request module to make get request to an API and console log the received data.
JavaScript
// Filename: index.js
const request = require('request')
// Request URL
let url = 'https://jsonplaceholder.typicode.com/todos/1';
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:
Make sure you have to install express and request modules using the following commands:
npm install request
npm install express
Run the index.js file using the 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.
Similar Reads
Node.js require Module The primary object exported by the require() module is a function. When NodeJS invokes this require() function, it does so with a singular argument - the file path. This invocation triggers a sequence of five pivotal steps: Resolving and Loading: The process begins with the resolution and loading of
3 min read
NodeJS Modules In NodeJS, modules play an important role in organizing, structuring, and reusing code efficiently. A module is a self-contained block of code that can be exported and imported into different parts of an application. This modular approach helps developers manage large projects, making them more scal
6 min read
NodeJS HTTP Module In NodeJS, the HTTP module is a core built-in module that enables developers to create and manage HTTP servers. It plays a crucial role in handling server-side HTTP requests and responses, allowing for seamless communication between clients and servers. In this article, we will dive into the NodeJS
5 min read
What are modules in Node JS ? In NodeJS, modules are encapsulated units of code that can be reused across different parts of an application. Modules help organize code into smaller, manageable pieces, promote code reusability, and facilitate better maintainability and scalability of NodeJS applications. Types of Modules:Core Mod
2 min read
What are Modules in Node.js ? In Node.js Application, a Module can be considered as a block of code that provide a simple or complex functionality that can communicate with external application. Modules can be organized in a single file or a collection of multiple files/folders. Almost all programmers prefer modules because of t
5 min read