Created
October 31, 2012 15:38
-
-
Save kevinohara80/3987729 to your computer and use it in GitHub Desktop.
Move socket.io setup to module for express 3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = express(); | |
var server = require('http').createServer(app); | |
var io = require('./ioinit')(server); | |
server.listen(80); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = require('socket.io'); | |
module.exports = function(server) { | |
io.listen(server); | |
// all setup and config goes here | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); | |
socket.on('my other event', function (data) { | |
// | |
}); | |
}); | |
// return the io instance | |
return io; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment