title: How to download file with Axios in node.js and write to the response
body: <p>I have the following video</p>
  <p>URL: <a href="https://static.videezy.com/system/resources/previews/000/000/161/original/Volume2.mp4" rel="nofollow noreferrer">https://static.videezy.com/system/resources/previews/000/000/161/original/Volume2.mp4</a></p>
  <p>and want to download it with <code>Axios</code> chunk by chunk and write to the response (send to client)</p>
  <p>Here, I do not know how to use <code>Range Header</code></p>
  <pre><code>const express = require('express')
  const app = express()
  const Axios = require('axios')
  
  
  app.get('/download', (req, res) =&gt; {
      downloadFile(res)
  })
  
  async function downloadFile(res) {
      const url = 'https://static.videezy.com/system/resources/previews/000/000/161/original/Volume2.mp4'
  
      console.log('Connecting …')
      const { data, headers } = await Axios({
          url,
          method: 'GET',
          responseType: 'stream'
      })
  
  
      const totalLength = headers['content-length']
      let offset = 0
  
      res.set({
          &quot;Content-Disposition&quot;: 'attachment; filename=&quot;filename.mp4&quot;',
          &quot;Content-Type&quot;: &quot;application/octet-stream&quot;,
          &quot;Content-Length&quot;: totalLength,
          // &quot;Range&quot;: `bytes=${offset}` // my problem is here ....
      });
  
      data.on('data', (chunk) =&gt; {
          res.write(chunk)
      })
  
      data.on('close', function () {
          res.end('success')
      })
  
      data.on('error', function () {
          res.send('something went wrong ....')
      })
  }
  
  
  const PORT = process.env.PORT || 4000
  app.listen(PORT, () =&gt; {
      console.log(`Server is running on port: ${PORT}`)
  })
  </code></pre>