[root@zexu websocket_start]# npm ls -g installed npm WARN ls doesn't take positional args. Try the 'search' command npm WARN websocket-server@1.4.04 package.json: bugs['web'] should probably be bugs['url'] /usr/lib ├─┬ npm@1.1.2 │ ├── abbrev@1.0.3 │ ├── block-stream@0.0.5 │ ├── fast-list@1.0.2 │ ├── fstream@0.1.12 │ ├── graceful-fs@1.1.5 │ ├── inherits@1.0.0 │ ├── ini@1.0.2 │ ├── lru-cache@1.0.5 │ ├── minimatch@0.1.5 │ ├── mkdirp@0.3.0 │ ├── node-uuid@1.3.3 │ ├── nopt@1.0.10 │ ├── proto-list@1.0.0 │ ├── read@0.0.1 │ ├── request@2.9.151 │ ├── rimraf@2.0.1 │ ├── semver@1.0.13 │ ├── slide@1.1.3 │ ├── tar@0.1.12 │ └── which@1.0.3 └── websocket-server@1.4.04 [root@zexu websocket_start]# npm ls installed npm WARN ls doesn't take positional args. Try the 'search' command /home/qonco/workspace/JS/websocket_start (empty) [root@zexu websocket_start]# node > require("websocket-server"); Error: Cannot find module 'websocket-server' at Function._resolveFilename (module.js:332:11) at Function._load (module.js:279:25) at Module.require (module.js:354:17) at require (module.js:370:17) at repl:1:1 at REPLServer.eval (repl.js:80:21) at repl.js:190:20 at REPLServer.eval (repl.js:87:5) at Interface. (repl.js:182:12) at Interface.emit (events.js:67:17) >
Asked
Active
Viewed 4.6k times
18

Thetsu
- 345
- 2
- 3
- 6
2 Answers
60
You have installed the module globally. Go to your app and try this to link the global to your application folder. Like so:
sudo npm link <MODULeNAME>

Youssouf Oumar
- 29,373
- 11
- 46
- 65

Toni
- 617
- 1
- 4
- 5
-
3This should be the top answer, it is a much more concise/easy way of locally installing, and allows you to have the module installed once globally. – Bloodyaugust Nov 16 '12 at 23:03
-
1I was doing `sudo npm link` only and couldn't find the module even if declared properly in the `package.json` file. Adding the `
` argument solved it. – Yanick Rochon Nov 14 '13 at 07:13
17
Have you installed the module with the -g
option?
I think that not every module is meant to be installed globally, instead, try installing it locally for the project you are creating (npm install), and check if the error persists.

Youssouf Oumar
- 29,373
- 11
- 46
- 65

Javo
- 627
- 6
- 4
-
Thank you ! I install locally and it works. Why is it different between locally and globally? Is not that node will find modules both globally and locally? – Thetsu Mar 14 '12 at 15:38
-
7If you want to just require('something'); it is better to install it locally, otherwise, you have to require('{PREFIX}something'), where prefix is the path to where yo have installed it globally. Check out this [blog post](http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/) , and, as it says, generally the rule of thumb is to install things locally if you are going to use them in your app, and globally if you are going to use them from the command line. – Javo Mar 14 '12 at 21:16
-
If are running a Node.js script, e.g. `~/bin/my-awesome-script.js`, Node.js will look for the module in that script's folder, not the current folder from you run the script. So in this case, make sure to run the `npm install …` from `~/bin`. – avernet Feb 27 '13 at 23:21
-
-1 for this. It does not work well and is rather messy. In my case, I needed the xpath module and npm tried to install xpath and all its dependencies locally in my project. The Tony's solution worked as it has only added a symlink to the already globally installed xpath module. – asiby Jan 11 '14 at 17:19
-
NPM installs modules locally on purpose. Made a quick search on google for an official statement about this, and here you have https://github.com/npm/npm/issues/918#issuecomment-1163447 EDIT: In fact, it's covered in the FAQs https://npmjs.org/doc/faq.html – Javo Jan 22 '14 at 16:29