0
I have a program that downloads the file that is passed to him, follows the code
function Download(arquivo) {
download("https://dumps.wikimedia.org/ptwiki/20190801/" + arquivo).then(
data => {
fs.writeFileSync(__dirname + "/downloads/" + arquivo, data);
console.log("Download concluido, arquivo " + arquivo);
}
);
}
I have another list that has all the files that must be downloaded through this function ,it is contained inside an array . If I do
Download(lista[posicaoDoArquivoQueQueroBaixar]) ;
It makes the Download correctly,now if I do a go, or foreach to automatically download, it give an error by calling multiple Downloads at the same time,
lista.forEach(arquivo =>{
Download(arquivo);
});
That’s the mistake you make
(node:15351) UnhandledPromiseRejectionWarning: HTTPError: Response code 503 (Service Temporarily Unavailable)
at EventEmitter.ee.on.res (/home/raellopes/Área de Trabalho/Trabalho/split xml document/node_modules/got/index.js:482:24)
at EventEmitter.emit (events.js:198:13)
at getResponse (/home/raellopes/Área de Trabalho/Trabalho/split xml document/node_modules/got/index.js:320:5)
at Immediate.setImmediate (/home/raellopes/Área de Trabalho/Trabalho/split xml document/node_modules/got/index.js:147:6)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
(node:15351) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15351) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Is there any way I could use for or foreach but the next loop would only run after the Download is completed?
(Note, the list has more than 60 files, to be exact 67, I tested running one at a time Download(list[x]) where X is the position from 0 to 67 and the download is done correctly, the error only give if I call more than 3x the Download at the same time)
I’m in doubt again,Can you call me in Whats to give me a boost? (98) 98307-9191
– mecatrônica com reciclagem