That's all. Then I try to use socket.io with this line: var io = require('socket.io').listen(app);
And it output an error: Error: Cannot find module 'socket.io'
at Function.Module._resolveFilename (module.js::)
at Function.Module._load (module.js::)
at Module.require (module.js::)
at require (module.js::)
at Object.<anonymous> (F:\nodejs\chat.js::)
at Module._compile (module.js::)
at Object.Module._extensions..js (module.js::)
at Module.load (module.js::)
at Function.Module._load (module.js::)
at Function.Module.runMain (module.js::)
I've tried all suggested method like cleaning cache, reinstalling nodejs or changing socket.io module path. Unfortunately, all of those solutions didn't solve this problem.
This terrible error killed my whole day. I greatly appreciate any help.
解决方法:
Try to execute npm install socket.io
in the folder where your node.js file is (where you require the module). npm creates a folder node_modules
wherever you execute npm install socket.io
and you probably didn't do this in the correct folder.
npm install supervisor -g
did work because -g is the global flag and you can basically do that anywhere.