title: Calling socket.io from rest api in node
body: <p>I am trying to emit a socket.io event from my restful api.</p>
  
  <p>My current setup looks something like this:</p>
  
  <p>app.js
  setups an express app and creates all the necessary routes like:</p>
  
  <pre><code>var app = express();
  ...
  var routesApi = require('./app_api/routes/index');
  app.use('/api', routesApi);
  module.exports = app;
  </code></pre>
  
  <p>server.js
  creates a server and hooks up both express app and socket.io</p>
  
  <pre><code>var http = require('http');
  var server = http.createServer(app);
  
  require('../app_server/controllers/socket.js').socketServer(server);
  </code></pre>
  
  <p>Everything works and I can successfully fire a socket event from the client, process it inside socket.js and emit the results.</p>
  
  <p>However, what I am trying to do is call socket.js method from my restful api and I can't figure out how to hook that up.</p>
  
  <p>Since socket server is initialized inside server.js and my api routing is hooked up in app.js, I am not sure what's the proper way of getting them to talk to each other.</p>
  
  <p>Thank you</p>