title: NodeJS, Express, and eventful Socket.io
body: <p>I want to build a NodeJS API so that when I hit an endpoint, the app will trigger an event that will cause its unique socket connection to <code>emit</code> a message to its listeners. I have built a solution before using Python/Django, Redis, and NodeJS/Socket.io with Django as the API and Redis as the 'event trigger', but I would like to consolidate the different technologies into NodeJS and Socket.io.</p>
  
  <p>I tried moving the <code>socket.emit()</code> code into different modules and then <code>app.use()</code>'d those modules, but the code broke because it didn't have an instance of the socket.</p>
  
  <p>I also know that you can broadcast to all socket connections inside on an endpoint, for example:</p>
  
  <pre><code>app.use('socket.io/help', function(req, res) {
      console.log(req.query);
      io.sockets.emit('help_message', 'You should help me.');
  
      res.send('help msg sent');
  });
  </code></pre>
  
  <p>But I am looking for a way that allows a client (that doesn't have a socket connection) to hit an endpoint and pass a query param that tells NodeJS which of its connected sockets to send a message to.</p>
  
  <p>Is this possible? Or am I trying to fight the framework? e.g., is there a different way of doing this with different JS WebSocket frameworks/technologies?</p>