Error: Cannot find module 'socket.io/node_modules/redis' on Mac

I am trying to run this example ( http://maxburstein.com/blog/realtime-django-using-nodejs-and-socketio/ ) but I am getting this error:

module.js:340
    throw err;
          ^
Error: Cannot find module 'socket.io/node_modules/redis'
    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 Object.<anonymous> (/Users/felipemoran/Desktop/django-realtime-tutorial-master/nodejs/chat.js:7:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

      

What I have done so far:

  • Unpack source files - ok
  • Start Redis server (by typing on terminal redis-server

    ) - ok
  • Start the Django server (by typing in another window python manage.py runserver

    while in the propper folder) - ok

The next step is to run the command in the third terminal window node chat.js

, and in the nodejs folder there are folders from the example files, but I get this error.

I am on Mac OS X Maverics, I installed node.js from the official mac installer and I installed socket.io using the npm command.

I also tried to run rpm install socket.io -g

, rpm install -g socket.io

those with two sudo

and run these commands from nodejs folder, but still have no success.

Thank!

+3


source to share


1 answer


Running npm install socket.io

installs the latest version from npm , which is now 1.1.0

. Your tutorial uses a version 0.9

and has changed a lot from this to 1.0

, including using the Redis adapter. As the tutorial doesn't use package.json to manage dependencies you ended up with the wrong version.

You can either update the server code to work with the latest one socket.io

(for which you need to install socket.io-redis ) or check out the latest version from the branch 0.9

by running npm view socket.io versions

and then installing npm install socket.io@0.9.17

.



And please remove the global settings, later they will cause gray hair ( npm uninstall -g socket.io

).

+2


source







All Articles