Skip to content
Related Articles

Related Articles

Node.js Request Module

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Expert
  • Last Updated : 08 Oct, 2021

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:

  1. It is easy to get started and easy to use.
  2. It is widely used and popular module for making HTTP calls.

Installation of request module:

  1. You can visit the link Install Request module. You can install this package by using this command.
    npm install request
  2. After installing request module you can check your request version in command prompt using the command.
    npm version request
  3. 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
    // Printing body

Steps to run the program:

  1. The project structure will look like this:
    project structure
  2. Make sure you have install express and request module using following commands:
    npm install request
    npm install express
  3. Run index.js file using below command:
    node index.js

    Output of above command

So this is how you can use the request module for making HTTP calls. It is very simple and easy to use.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!