I'm trying to build an ExpressJs based app using the submodule architecture suggested by tjholowaychuk.
I'd like to also have some realtime socket interaction, so I'm trying to integrate socket.io. I'm struggling to find the best way to do this as a sub app and allow both Express and socket.io listen together.
You could put all socket.io related code in a separate file:
// socketio.js
var sio = require('socket.io');
module.exports = function(server) {
var io = sio.listen(server);
io.sockets.on('connection', ...);
return io;
};
// app.js
var app = require('express')(),
server = require('http').createServer(app),
io = require('./socketio')(server);