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.