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
Asked
Active
Viewed 290 times
1
-
You could use server-side code - I *believe* you can do it in Node, but that's a guess. Also, why don't you want to use the browser? You can write a script that takes a URL, and downloads the file for you. And there's ``...you have lots of options, but browsers are there and simple. – Jack Bashford Jun 01 '19 at 07:29
-
Ya I want to do it on Node only, Dont wanna use a browser... – Jun 01 '19 at 07:31
-
1This might help yoy https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries – chintuyadavsara Jun 01 '19 at 08:04
1 Answers
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