title: How to emit an event in socket.io from the routes file?
body: <p>This is my app configuration</p>
  
  <p>app.js</p>
  
  <pre><code>//SERVER
  var server = app.listen(3000, function(){
      console.log("Express server listening on port %d in %s mode", app.get('port'),
      app.settings.env);
  });
  //SOCKET.IO
  var io = require('./socket.io').listen(server)
  </code></pre>
  
  <p>/socketio</p>
  
  <pre><code>var socketio = require('socket.io')
  
  module.exports.listen = function(app)
  {
      io = socketio.listen(app);
      io.configure('development',function()
      {
              //io.set('transports', ['websocket', 'xhr-polling']);
              //io.enable('log');
      });
      io.configure('production',function()
      {
          io.enable('browser client minification');  // send minified client
          io.enable('browser client etag');          // apply etag caching logic based on version number
          io.set('log level', 1);                    // reduce logging
          io.set('transports', [                     // enable all transports (optional if you want flashsocket)
              'websocket'
            , 'flashsocket'
            , 'htmlfile'
            , 'xhr-polling'
            , 'jsonp-polling'
          ]);
      });
      io.sockets.on('connection', function (socket)
      {
          console.log("new connection: "+socket.id);
          socket.on('disconnect',function(){console.log("device "+socket.id+" disconnected");});
  
          socket.emit('news', { hello: 'world' });
          socket.on('reloadAccounts',function(data)
          {
              var accounts=['account1','account2']
              socket.emit('news',accounts)
          });
      });
      return io
  }
  </code></pre>
  
  <p>/routes</p>
  
  <pre><code>    exports.newAccount=function(fields,callback)//localhost:3000/newAccountForm
      {
  //... bla bla bla config db connection bla bla bla
              db.collection('accounts').insert(fields,function(err,result)
              {
                  if(err)
                  {
                      console.warn(err);
                      db.close();
                      return callback(err,null);
                  }else{
                      if(result)
                      {
                          db.close();
                          return callback(null,result);
                                  socket.emit('new account created',result) // i want to emit a new event when any user create an account
  
                      }else{
                          db.close();
                          return callback('no se consigue resultado',null);
                      }
                  }
              })
          });
      }
  </code></pre>
  
  <p>How to emit an event in socket.io from the routes file?</p>