I did sudo npm install -g ws and then wscat thing works. however, if I go to node and do require('ws') I get
Error: Cannot find module 'ws'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
why is that? If I do npm without '-g' then, and try require again, it works.
Here is log in case it helps:
localhost:Documents makc$ sudo npm install -g ws
Password:
npm http GET https://registry.npmjs.org/ws
npm http 304 https://registry.npmjs.org/ws
unbuild [email protected]
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/options
npm http 304 https://registry.npmjs.org/tinycolor
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/options
/usr/local/bin/wscat -> /usr/local/lib/node_modules/ws/bin/wscat
> [email protected] install /usr/local/lib/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/bufferutil.node
SOLINK_MODULE(target) Release/bufferutil.node: Finished
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/validation.node
SOLINK_MODULE(target) Release/validation.node: Finished
[email protected] /usr/local/lib/node_modules/ws
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
unless you're looking to install a cli utility, never use install -g.
Exactly what @superjoe30 said, and it's not something that we, ws can fix. It's now node deals with modules.
I don't get it. -g stands for globally, right? I want to install ws module globally. How do I do it?