3

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?

nesQuick
  • 33
  • 1
  • 5
  • Where did you install socket.io ? Did you install it in the folder where your server.js file is? – Raynos Apr 22 '11 at 12:37
  • I installed it with npm, I have no idea where npm stores the intstalled libarys. – nesQuick Apr 22 '11 at 12:45
  • But find says: `find / -name socket.io -type d /usr/lib/node/.npm/socket.io /usr/lib/node/.npm/socket.io/0.6.17/package/lib/socket.io /usr/lib/node/.npm/.cache/socket.io /usr/lib/node/.npm/.cache/socket.io/0.6.17/package/lib/socket.io ` – nesQuick Apr 22 '11 at 12:46
  • @nesQuick if that's on the server it should have worked. unless permissions etc are not set up properly. – Raynos Apr 22 '11 at 12:56
  • But it doesn't, thats the reason why i'm here :( – nesQuick Apr 22 '11 at 12:57
  • Try giving an absolute path to socket.io – 0xff0000 Apr 25 '11 at 06:54

2 Answers2

5
  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!

duality_
  • 17,738
  • 23
  • 77
  • 95
0

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.

ObiHill
  • 11,448
  • 20
  • 86
  • 135