Here's a simple downloadFile() function to download any file using axios in Node.JS.

How To Implement the Axios File Download in Node.js

Axios is a great http library for both browser and node.js. If you are not familiar with this cool tool yet, please have a look at github repo Axios.

npm install axios --save

What we need

  • Method: GET
  • responseType: stream

we will use node.js stream api (fs.createWriteStream) to write the file.

That's it, your quick file downloader is ready with this little snippet.

Enjoy!