node.js: cannot find module 'request' node.js: cannot find module 'request' linux linux

node.js: cannot find module 'request'


Go to directory of your project

mkdir TestProjectcd TestProject

Make this directory a root of your project (this will create a default package.json file)

npm init --yes

Install required npm module and save it as a project dependency (it will appear in package.json)

npm install request --save

Create a test.js file in project directory with code from package example

var request = require('request');request('http://www.google.com', function (error, response, body) {  if (!error && response.statusCode == 200) {    console.log(body); // Print the google web page.  }});

Your project directory should look like this

TestProject/- node_modules/- package.json- test.js

Now just run node inside your project directory

node test.js


You should simply install request locally within your project.

Just cd to the folder containing your js file and run

npm install request


I had same problem, for me npm install request --save solved the problem. Hope it helps.