cannot find socket.io-client on nodejs server running

cannot find socket.io-client on nodejs server running

Problem

clean install node ,express, socket.io on linux environment using npm. I try to runsocket.io sample from socket.io official source, I am getting error socket.io-client module not found on command line.

I work around few hours to solve this. but I didnt found any soutions.

Error :

module.js:337
    throw new Error("Cannot find module '" + request + "'");
          ^
Error: Cannot find module 'socket.io-client'
    at Function._resolveFilename (module.js:337:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:359:17)
    at require (module.js:375:17)
    at Object.<anonymous> (/home/rajuk/Documents/nodeSamples/node_modules/socket.io/lib/socket.io.js:12:14)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:32)
    at Function._load (module.js:311:12)
    at Module.require (module.js:359:17)

socket.io install result

socket.io@0.9.14 /usr/local/lib/node_modules/socket.io 
├── base64id@0.1.0
├── policyfile@0.0.4
├── redis@0.7.3
└── socket.io-client@0.9.11

here is my code(app.js)

var app = require('express')()
  , server = require('http').createServer(app)
  , io = require('socket.io').listen(server);

server.listen(80);

app.get('/', function (req, res) {
  res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

and node_modules directory contains socket.io and express packages.

I am trying to run server like this

$ node app.js

how to resolve it?

Problem courtesy of: Konga Raju

Solution

Clone this git depositery : https://github.com/yrezgui/socket.io-simple-demo

And tell me if you still have an error.

Solution courtesy of: Yacine Rezgui

Discussion

Leave a Reply

Your email address will not be published. Required fields are marked *