Reputation: 608
I install request package using npm. It appears to be located here: /usr/local/lib/node_modules/request/
var request = require("request");
request("http://www.google.com", function(error, response, body) {
console.log(body);
});
module.js:340 throw err; ^ Error: Cannot find module 'request'...
What do I need to alter or perform? Further info, MAC OSX, node-v0.10.26.pkg, sudo -H npm install -g request, no errors
Upvotes: 2
Views: 4038
Reputation: 12420
I think you have installed the package using the -g
flag (global).
That's not how you should have installed the package.
To fix your problem, install the package locally:
npm install request
Or use a package.json
file to persist the dependency:
{
"name": "test",
"version": "0.1.0",
"dependencies": {
"request": "*"
}
}
Upvotes: 6
Reputation: 10092
Use advice by @Florent. Your direct problem, however, is that the global location is not known to node. If you still want to enable it, set the value of NODE_PATH to /usr/local/lib/node_modules (on Mac OS X in /etc/launchd.conf to make it available to all on boot).
Upvotes: 0
Reputation: 557
You need to install the package in your project directory, not globally. So run npm install
from your project directory without the -g
flag.
Upvotes: 2