title: In NodeJS, how to correctly create a docx file download function via a REST endpoint?
body: <br/>
  I've been trying to create a function that lets client download a docx file from NodeJS server.<br/>
  With some research, I could successfully download the file but was unable to open it.<br/>
  Below is my try:
  <ul>
  <li>On Server, I have a post endpoint:</li>
  </ul>
  <pre><code>router.post(&quot;/download&quot;, async (req, res, next) =&gt; {
    // declare: _filepath, _filename
    ...
    let stream = fs.createReadStream(_filepath, { bufferSize: 64 * 1024 })
    res.setHeader('Content-Disposition', `attachment; filename=${_filename}`);
    res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessing');
    stream.pipe(res)
    ...
    // handle stream events: error, close
  })
  </code></pre>
  <ul>
  <li>At Client, I have:</li>
  </ul>
  <pre><code>// declare _reqBody
  ...
  await axios.$post(&quot;/download&quot;, _reqBody, { responseType: 'blob' })
    .then(response =&gt; {
      let blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.wordprocessing' });
      let url = window.URL.createObjectURL(blob);
      let a = document.createElement('a');
      a.href = url;
      a.download = 'myfile.docx';
      document.body.appendChild(a);
      a.click();
    });
  </code></pre>
  <p>Since this code makes me available to download but the file seemed to be corrupted, could someone give me a hand on this?<br/>
  From my googling, the response should look like<br/>
  <a href="https://i.stack.imgur.com/UPG22.png" rel="nofollow noreferrer">expected</a><br/>
  but what I actually get was<br/>
  <a href="https://i.stack.imgur.com/IoDdR.png" rel="nofollow noreferrer">actual</a></p>