How to download a file using Node.js

To download a file using Node.js, use one of the the many npm request libraries.


For example, an MP4 file can be downloaded using node-fetch.

Install node-fetch:

$ npm install node-fetch

The URL of the MP4 file is:

Create a JavaScript file index.js that downloads the MP4:

// index.js
const fetch = require('node-fetch');
const { writeFile } = require('fs').promises;

const url =

(async () => {
  const response = await fetch(url);
  const buffer = await response.buffer();
  await writeFile('test.mp4', buffer);

Run the script to download the MP4:

$ node index.js


Please support this site and join our Discord!