title: How to send form data in node.js
body: <p>I am able to get to the server but unable to post my form data.
  How should I post the form data with the https request?
  I am using form-data library for form-data, and https request for post call.
  When I run the following code, I am able to reach the service, but the service gives a response saying that the form data is not submitted.</p>
  
  <pre class="lang-js prettyprint-override"><code>var https = require('https');
  var FormData = require('form-data');
  //var querystring = require('querystring');
  var fs = require('fs');
  var form = new FormData();
  
  connect();
  
  function connect() {
      username = "wr";
      password = "45!"
  
      var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
      var options = {
          hostname: 'trans/sun.com',
          port: 443,
          path: '/transfer/upload-v1/file',
          method: 'POST',
          rejectUnauthorized: false,
          headers: {
              'Authorization': auth,
              'Content-Type': 'application/json',
              //'Content-Length': postData.length
          }
      };
  
      form.append('deviceId', '2612');
      form.append('compressionType', 'Z');
      form.append('file', fs.createReadStream('/Mybugs.txt'));
  
      var req = https.request(options, function(res) {
          console.log("statusCode: ", res.statusCode);
          //console.log("headers: ", res.headers);
          res.setEncoding('utf8');
          res.on('data', function(d) {
              console.log(d)
          });
      });
  
      req.write(form + '');
      req.end();
  
      req.on('error', function(e) {
          console.error(e);
      });
  }
  </code></pre>