download a file nodejs

  1. Use the fs module to require the built-in Node.js file system module:
const fs = require('fs');
  1. Use the https or http module to make a GET request to download the file from a URL:
const https = require('https');
const fileUrl = 'https://example.com/file.zip';
  1. Create a writable stream using fs.createWriteStream to save the downloaded file locally:
const file = fs.createWriteStream('file.zip');
  1. Use https.get or http.get to initiate the GET request and save the response to the file stream:
https.get(fileUrl, function(response) {
  response.pipe(file);
});