nox0311
nox0311

Reputation: 76

Error in socket.io of node

i have used the following code in express + socket.io

app.io.route('customers', {
    create: function (req) {
        console.log("create");
    },
    update: function (req) {
        console.log("update");
    },
    remove: function (req) {
        console.log("remove");
    },
});

and I am getting the error as
cannot find method 'route' of undefined

I have used the following:
var express=require('express.io');
var app = require('express.io')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

Does any body know how to solve this error?

Upvotes: 0

Views: 289

Answers (1)

Raul Rene
Raul Rene

Reputation: 10280

It means that app.io is undefined, probably because you did not import it properly. To work with socket.io you have to import it and make it listen on your server:

var io = require('socket.io').listen(app.server);

io.sockets.on('connection', function(socket) {

});

However, I suspect you are using express.io, and as per their documentation you should do:

app = require('express.io')();
app.http().io();

app.io.route('customers', ...);

Upvotes: 3

Related Questions