title: NodeJS: combination of post requests and socket.io
body: <p>I'm creating a web application which has two web portals, and a node server. First portal sends HTTP requests(POST) while the second web portal should show them. Then a user will type some text and send it back to the server through the socket and it should redirect it to the first portal. I've used socket.io for the communication happen between the second portal and the server, while the first one does it though post. I'm struggling with finding a way to receive the answer from the second web portal and send the answer back to the first one. Here's the code.</p>
  
  <pre><code>var app = require('express')();
  var server = require('http').Server(app);
  var io = require('socket.io')(server);
  
  server.listen(5700);
  
  io.on('connection', function (socket) {
    console.log("connected" + socket.id);
  
  });
  
  app.post('/server', rawBody, function(req, res, next){
  
    var question = req.query.question;
    io.emit('question', {data: question});
  
    io.on('answer', function(data) {
      var body = {
        response: "data.answer"
      };
  
      res.json(body);
    });
  });
  </code></pre>
  
  <p>As I've found <code>io.on('answer', function(data)</code> is incorrect. But what I need is something like this:</p>
  
  <pre><code>io.on('answer', function(data) {
          var body = {
            response: "data.answer"
          };
  
          res.json(body);
        });
  </code></pre>
  
  <p>Could you please tell me how should I get the answer back from the socket and upon receive it, send the reply back to the first web portal. </p>