Skip to content

Instantly share code, notes, and snippets.

@mkhizeryounas
Last active June 11, 2018 23:48
Show Gist options
  • Save mkhizeryounas/2dfbfc00a30c3671a7b158017e95e8cf to your computer and use it in GitHub Desktop.
Save mkhizeryounas/2dfbfc00a30c3671a7b158017e95e8cf to your computer and use it in GitHub Desktop.
Socket io implementation in express generator
/****** bin/www ******/
// After -> server.listen(port);
// Addd the following for Socket.IO
var io = require('socket.io').listen(server);
require('../custom_modules/socket-helper')(io);
/****** socket-helper.js module ******/
module.exports = function (io) {
io.on('connection', function(socket){
console.log(socket.id);
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('chat_message', function(msg){
console.log( msg);
io.emit('chat_message',"-->" + msg);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment