title: How to emit a socket.io response within post request in NodeJS
body: <p>I have a node server running a react application, integrated with Socket.io. All works fine. I also have an external application that uses the same data. What I want to do is, when the data changes, post to my node server and then in the response, emit to any data to users who are currently subscribed to the socket.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//SERVER CODE LIVES ABOVE HERE...
  
  const io = require('socket.io')(server);
  
  io.on('connection', (socket) =&gt; {
    socket.on('create data', function(data) {
      //a place to create data, once complete triggers everyone subscribed to get an update.
      socket.emit('data created', data);
    });
  
  });
  
  
  app.post('/api/datacreated/', function(req, res) {
    //HOW DO I EMIT IN HERE?! - this is coming from an external resource
    socket.emit('data created', data);
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>Cheers for any time you've got!</p>