title: POSTing from Angular to Node. Getting empty body on node
body: <p>Im posting two fields in Angular to a NodeJs endpoint.</p>
  <p>I usually post on the body and everything is perfect at Node, but this time, I have to post a form to upload a file.</p>
  <p>So this is my code for posting the form data (Angular side):</p>
  <pre><code>var APIURL = sessionStorage.getItem('endPoint') + &quot;profile/updateeocoverage&quot;; 
  let formData = new FormData();
  formData.append(&quot;data&quot;, JSON.stringify(this.payLoad));
  if (this.eofile) {
    formData.append(&quot;myfile&quot;, this.eofile, this.eofile.name);
  }
  this.httpClient.post(APIURL,  formData).subscribe(
    result =&gt; {
    ....
  </code></pre>
  <p>My problem is that I always retrieved the body at node as follows:</p>
  <pre><code>router.post('/updateeocoverage', async   (req, res, next) =&gt; {
      console.log(req.body)
      return;
      ....
  </code></pre>
  <p>But with the method Im using now in Angular, req.body is retrieving {}</p>
  <p>Is the POST wrong, or the router wrong at Node side?</p>
  <p>Thanks.</p>
  <p><strong>UPDATE ON PABLO'S ANSWER BELOW (SOLUTION PROVIDED) for whoever runs into this issue:</strong></p>
  <p>Using Multer solved the problem, but as he said some workaround is needed as to set the file name, but most important it is required to authenticate the user, so:</p>
  <pre><code>const multer = require('multer')
  const path = require('path')
  </code></pre>
  <p>To authenticate the user, I send the authentication parameters on the header. Sending it as formdata.append didn't work for me. This sets true or false to upload the file, otherwise anyone can upload anything to the route:</p>
  <pre><code>async function authenticateUser(req, file, cb) {
      let tempcred = JSON.parse(req.headers.data)
      let credentials = tempcred.credentials;
      let userData = await utils.isValidUser((credentials), false);
      if (userData.isValid == false) {
          cb(null, false)
          return;
      }
      else {
          cb(null, true)
      }
  }
  </code></pre>
  <p>Then, since Multer uploads the file with a random name, and I need to save it with the user ID name and the file extension, I do the following:</p>
  <pre><code>var storage = multer.diskStorage({
      destination: function (req, file, cb) {
          cb(null, 'uploads/eofiles/')
      },
      filename: async function (req, file, cb) {
          let tempcred = JSON.parse(req.headers.data)
          let credentials = tempcred.credentials;
          let userid = await utils.decrypt(credentials.userid, process.env.SECRET);
          cb(null, userid + path.extname(file.originalname))
      }
  });
  </code></pre>
  <p>Finally, I declare the upload variable for using it with Multer:</p>
  <pre><code>var upload = multer({ storage: storage, fileFilter: authenticateUser })
  </code></pre>
  <p>And set the router:</p>
  <pre><code>router.post('/updateeofile', upload.single(&quot;myfile&quot;), async (req, res, next) =&gt; {
  let filename = req.file.filename //gets the file name
  ...
  ...
  do my stuff, save on database, etc
  ...
  ...
  });
  </code></pre>
  <p>For the record, &quot;myfile&quot; is the input file id.</p>
  <p>And this is how I upload the file from Angular:</p>
  <pre><code>var APIURL = sessionStorage.getItem('endPoint') + &quot;eoset/updateeofile&quot;;    
      const httpOptions = {
        headers: new HttpHeaders({
          'data': `${JSON.stringify(this.payLoad)}`
        })
   };
   let formData = new FormData();
      if (this.eofile) {
        formData.append(&quot;myfile&quot;, this.eofile, this.eofile.name);
      }
      this.httpClient.post(APIURL, formData, httpOptions).subscribe(
        result =&gt; {
  ...
  ...
  ...
   },
        error =&gt; {
  
  });
  </code></pre>
  <p>I spent 6 hours on this today. I hope this helps you and saves you some time.</p>