title: POST data through socket.io to app.js
body: <p>I would like to:</p>
  
  <ul>
  <li>retrieve data entered from input forms.</li>
  <li>send the data through socket.io and send console log saying done</li>
  <li>receive the data on express app.js</li>
  <li>insert the data into a mongodb database using mongoose.</li>
  </ul>
  
  <p>I understand emit messages but not sure how to post data through. thank you in advance</p>
  
  <p>my app.js is set up like this:</p>
  
  <pre><code>//app.js config ...
  
  var socket = io.listen(server);
  
  socket.on('connection', function(socket) {
     console.log('socket.io connected');
  });
  
  
  
  app.post('/go', function(req, res) {
  
    socket.on('data', function(data) {
      new Order({
        routeFrom : data.routeFrom,
        routeTo : data.routeTo,
        leaving: data.leaving
      }).save(function(err, docs) {
        if(err) { console.log("error"); }
        res.json(data);
      });
      socket.emit('callback', {done: 'Done'});
    });
  
  });
  </code></pre>
  
  <p>my index.ejs file:</p>
  
  <pre><code>  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code> var socket = io.connect('http://localhost:3000');
  
  $('#send').on('click', function() {
      $.post('/go', {
         socket.emit('data', {
          routeFrom: $('#rf').val(),
          routeTo: $('#rt').val(),
          leaving: $('#l').val()
         });
  
      });
  
    socket.on('callback', function(data) {
     console.log(data);
    });
  
  });
  </code></pre>
  
  <p></p>