Socket.io

Socket emit inside functions

// config/lib/socket.io.js
{
...
  // Add an event listener to the 'connection' event
  io.on('connection', function (socket) {
    config.files.server.sockets.forEach(function (socketConfiguration) {
      require(path.resolve(socketConfiguration))(io, socket);
    });
  });

// added this line below
app.set('socketio', io);

return server;
}

Second, I load this variable as 'app.get' which is like snipplet below:

// any server controller file, I want to emit, 
// in my case, user.profile.server.controller.js
{
var io = req.app.get('socketio');

...
io.emit('rom1', msg);