Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module 'socket.io'

[~]# node node.js

Error: Cannot find module 'socket.io'

[~]# node -v
v0.10.10

socket.io installed:

npm install socket.io

npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
like image 564
DmitriyB Avatar asked Jun 12 '13 05:06

DmitriyB


People also ask

What is Socket.IO in node JS?

Socket.IO is a library that enables real-time, bidirectional and event-based communication between the browser and the server. It consists of: a Node. js server: Source | API. a Javascript client library for the browser (which can be also run from Node.


3 Answers

Looks like you have installed socket.io in a different location to your current path. Either install globally like below:

npm install -g socket.io

Or reference the location you've installed to:

var io = require('../lib/socket.io'); 
like image 71
ajtrichards Avatar answered Sep 19 '22 10:09

ajtrichards


Thanks ajtrichards!

Just to add to the answer - in case you simple use

sudo npm install socket.io 

The installation path will be

/home/.../.npm/socket.io 

If you use sudo npm install -g socket.io

The installation path will be

/usr/local/lib/node_modules/socket.io 

In first case, I tried adding the socket.io path in global path variable but it did not work.

like image 37
suman1409 Avatar answered Sep 22 '22 10:09

suman1409


you might have installed but not added to the dependencies in package.json Use below command to install socket.io module

npm install socket.io --save

Hope this will resolve your problem..

like image 42
John Avatar answered Sep 23 '22 10:09

John