1

I want to download a file from https://www.sec.gov/Archives/edgar/full-index/2018/QTR1/company.zip and I want to specify a path for it to be saved on my computer, but I dont want to use any browser intermediate. Can someone guide me how to write a script in javascript to download the file from url and save it on my pc

1 Answers1

2

As chintuyadavsara said, filling in this answer with your url does the trick:

const https = require('https');
const fs = require('fs');

function go (src, dest) {
    const file = fs.createWriteStream(dest);
    const request = https.get(src, function(response) {
        response.pipe(file);
    });
}

go('https://www.sec.gov/Archives/edgar/full-index/2018/QTR1/company.zip', './company.zip');
ray
  • 26,557
  • 5
  • 28
  • 27