Hei, i need some help, what i want is to wait for all file from url finished downloaded(writen) and than when it finish it will run another function. in this code block that i wrote, the resolve will be ran first before waiting for all file finished writing and thats not what i want.
pages argument is a array of url.
so, if i use 'finish' callback, the callback will be run for every url that finish, the thing i want to do is wait for all of the url, and than run the resolve();
function urlDownload(TITLE, PAGES) {
const download = new Promise((resolve, reject) => {
PAGES.map((value, index) => {
request
.get(value)
.pipe(fs.createWriteStream(`folder/${TITLE}/${index}.jpg`))
.on("finish", () => console.log(`Finished downloading ${index}.jpg`));
});
resolve("Done");
});
download.then((resolve) => {
console.log(resolve);
});
}