Tuesday 6 June 2017

How to use socket.io events in a package?

I want to implement socket.io. It has worked fine 1 week ago (without express). Now, I'm trying to use express but I don't know how/where I can handle the socket.io-events.

My project structure looks like that:

| - bin - www - app.js - public - routes - file1.js - views - render_this.ejs

In my www, there is this code:

var server = http.createServer(app);

So, I can use socket.io:

var io = require('socket.io').listen(server);
io.on('connection', function(socket){
   console.log('user ' + socket.id + ' connected');
});

But I want to handle those "io.on(...) - events" in an other directory like routes/file1.js for example.

How is it possible?



via Alpha

No comments:

Post a Comment