title: NodeJS Send response after some task
body: <p>I'm developing a node application which listens for http requests, pulls out the parameters and passes them on to another application via websocket, returning the applications reply as a http response.</p>
  
  <p>Simplified code:</p>
  
  <pre><code>app -&gt; express instance
  ws -&gt; websocket object
  cbs -&gt; array to store key, value (callback functions)
  
  
  app.post('/someCall', function(req,res) {
      var msg = req.body;
      msg.cb_id = "cb_id|"+Date.now(); // create unique id for callback fn
      cbs[msg.cb_id] = function() { // save callback
          res.send('got reply from ws');
      }
      ws.send(msg); //forward to websocket
  }
  
  
  ws.on('message', function(message) { // fired when we get a response from 2nd application
      var msg = JSON.parse(message);
      if(typeof(cbs[msg.cb_id]) === 'function')) { // check if we have registered a callback
          cbs[msg.cb_id](); // execute the saved callback
          delete(cbs[msg.cb_id]); // remove
      }
  });
  </code></pre>
  
  <p>To simplify things further for now, the 2nd application is a node instance which just echos any message it receives. I can confirm the message gets back, however I keep getting <code>Error: Request aborted</code>.</p>
  
  <p>It seems as though the post handler falls through and the callback never gets called. I can verify that it does get called if I replace the function with say <code>console.log('it worked');</code> but can't get it to actually respond to the request.</p>
  
  <p>So I guess the question is how can I keep the request open until I get a reply from the 2nd application, is this the right approach?</p>