开发者

node.js with socket.io under debian 5 (lenny) exit with error

I installed node.js with the instructions from node.js wiki. So I put the debian sid sources in my sources list and installed node. After that I installed npm with the curl cmd from wiki site. I installed socket.io with npm. Everything till this point works without any errors.

But when I try to start my server I get this error:

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^ Error: Cannot find module 'socket.io'
    at Function._resolveFilename (module.js:320:11)
    at Function._load (module.js:266:25)
    at require (module.js:348:19)
    at Object.<anonymous> (/root/sockets/trunk/socketio/server.js:8:8)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
    at Function._load (module.js:297:12)
    at Array.<anonymous> (module.js:423:10)
    at EventEmitter._tickCallback (node.js:126:26)
开发者_开发知识库

I dont have any ideas why this won't work? Could anybody help?


  1. Go to the project folder. This is the folder where you run node your_server.js.
  2. Run npm install socket.io. This will add a directory under this project folder named node_modules, where, unsurprisingly, modules for this project are.
  3. Run the server with node your_server.js. This time it will work ;).

Enjoy!


You can reference socket.io directly in your javascript file.

If you installed socket.io using npm install socket.io -g it should have installed socket.io in a node_modules directory under /usr/local/lib. So pick up socket.io from there.

So in your script, reference socket.io like below:

var io = require('/usr/local/lib/node_modules/socket.io');

Then run node /wherever_your_script_is/your_script.js

Cheers.

P.S. Not sure how npm worked in the past, but today the above would work ok, I just tried it to make sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜