title: Sending form data in nodejs using https.request
body: <p>I am trying to post a request with my nodejs server to another server and then I have to save response in a file. I am using nodejs https.request module.</p>
  
  <p>This is my request:</p>
  
  <pre><code>    var formData = new FormData();
      formData.append('first',3);
      formData.append('second', '25');
      formData.append('source_file', fs.createReadStream(sourcefile));
      formData.append('source_image', fs.createReadStream(sourceimage));
  
  var options = {
      hostname: 'ip',
      path: '/api/path',
      method: 'POST'
  }
  var file = fs.createWriteStream("file.pdf");
  var req = https.request(options, (response) =&gt; {
      response.pipe(file);
      console.log("File saved");
      response.send("done")
    });
  
    req.on('error', (e) =&gt; {
      console.error(e);
    });
  
    req.write(formData);
    req.end();
  </code></pre>
  
  <p>But I am getting the error</p>
  
  <pre><code>First argument must be a string or Buffer
  </code></pre>
  
  <p>I tried sending my files using <code>formData.toString()</code> but on using this, error disappears but My files are not working and also I have sent data like this:</p>
  
  <pre><code> var formData = new FormData();
  formData = {
          first: 3,
          second: '25',
          source_file: fs.createReadStream(sourcefile),
          source_image: fs.createReadStream(sourceimage)
      };
  </code></pre>
  
  <p>How can I send my files to other server using this request. </p>
  
  <p>Thanks</p>