You can use HTTPS client and FileSystem from Node.js.
Here an example with an async function. This function also handle redirect which wget does for you.
const http = require("https");
const fs = require("fs");
/**
* @param {string} url
* @param {string} dest
* @returns {Promise<void>}
*/
function wget(url, dest) {
return new Promise((res) => {
http.get(url, (response) => {
if (response.statusCode == 302) {
// if the response is a redirection, we call again the method with the new location
wget(String(response.headers.location), dest);
} else {
const file = fs.createWriteStream(dest);
response.pipe(file);
file.on("finish", function () {
file.close();
res();
});
}
});
});
}
Please note that you need to use http
or https
module according to your URL
child_process.exec(cmd)
. – Vogue