jehara caduan
jehara caduan

Reputation: 3

NodeJS require error when running the server.js

I run into the following error when running node server.js:

enter image description here

Why does require throw an error? I am using Socket.IO, and my code in server.js is shown below:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');

server.listen(8890);
io.on('connection', function (socket) {

  console.log("new client connected");
  var redisClient = redis.createClient();
  redisClient.subscribe('message');

  redisClient.on("message", function(channel, message) {
    console.log("mew message in queue "+ message + "channel");
    socket.emit(channel, message);
  });

  socket.on('disconnect', function() {
    redisClient.quit();
  });

});

Upvotes: 0

Views: 84

Answers (1)

Michael Ramos
Michael Ramos

Reputation: 5817

Your issue is that you are using Socket.io v0.8.1. You can resolve this by at least installing v1.0.0. I recommend the latest stable release, if you have no requirements/restraints on upgrading from prior versions.

The require('io')(srv) signature was released in v1.0.0. Plus v0.8.1 dates back to 2011; that is a long time and much has changed in Node, as well as Express and Socket.io.

Here is more about transitioning from version v0.9 and below to v1.0.0+: http://socket.io/docs/migrating-from-0-9/

Here is where you can find version history of Socket.io: https://github.com/socketio/socket.io/blob/master/History.md

Upvotes: 3

Related Questions