Categories
JavaScript Answers

How to fix “cannot find module ‘request'” error with Node.js?

Spread the love

To fix "cannot find module ‘request’" error with Node.js, we install the request package.

To install it, we run

npm install request --save

Then we can use it with

const request = require("request");

request("http://www.example.com", (error, response, body) => {
  if (!error && response.statusCode === 200) {
    console.log(body);
  }
});

We call request to make a get request to http://www.example.com

And get the response with response from the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *