title: Sending data through POST request from a node.js server to a node.js server
body: <p>I'm trying to send data through a <code>POST</code> request from a node.js server to another node.js server. What I do in the "client" node.js is the following:</p>
  
  <pre><code>var options = {
      host: 'my.url',
      port: 80,
      path: '/login',
      method: 'POST'
  };
  
  var req = http.request(options, function(res){
      console.log('status: ' + res.statusCode);
      console.log('headers: ' + JSON.stringify(res.headers));
      res.setEncoding('utf8');
      res.on('data', function(chunk){
          console.log("body: " + chunk);
      });
  });
  
  req.on('error', function(e) {
      console.log('problem with request: ' + e.message);
  });
  
  // write data to request body
  req.write('data\n');
  req.write('data\n');
  req.end();
  </code></pre>
  
  <p>This chunk is taken more or less from the node.js website so it should be correct. The only thing I don't see is how to include username and password in the <code>options</code> variable to actually login. This is how I deal with the data in the server node.js (I use express):</p>
  
  <pre><code>app.post('/login', function(req, res){
      var user = {};
      user.username = req.body.username;
      user.password = req.body.password;
          ...
  });
  </code></pre>
  
  <p>How can I add those <code>username</code> and <code>password</code> fields to the <code>options</code> variable to have it logged in?</p>
  
  <p>Thanks</p>