title: how to get extra form fields in form-data in post Node.js
body: <p>Key-value pairs like <code>name</code> are appended to form-data in a client-side <code>XMLHttpRequest</code> and sent with file to be uploaded.</p>
  
  <p>How can I extract those values on the server side, which is using Node.js.   </p>
  
  <p><strong>Browser</strong>:</p>
  
  <pre><code>formdata = new FormData();
  for( var x = 0;x &lt; files.length;x = x+1){
      formdata.append('file',files[x]);
  }
  formdata.append('name',name);  //name appended here to form-data
  formdata.append('email',email);
  formdata.append('reason',reason);
  formdata.append('location',location);
  var xhr = new XMLHttpRequest();
  var url = "/sign_8081";
  xhr.open("POST" ,url);
  xhr.withCredentials = true;
  </code></pre>
  
  <p><strong>Node.js Server</strong>:</p>
  
  <pre><code>router.post('/sign_8081', (req, res) =&gt; {
      console.log("sign 8081called"+JSON.stringify(req.body))
      console.log(req.query.name);
      console.log(req.body.name); //want name key value in Node.js code 
      let body = '';
      var rb;
      req.on('data', chunk =&gt; {
          body += chunk.toString(); // convert Buffer to string
      });
      req.on('end', () =&gt; {      
          rb = parse(body)
          console.log(rb.name);
      });
      console.log(req.file.filename)
      res.send(req.file.filename)                
  });
  </code></pre>