Answer the question
In order to leave comments, you need to log in
How to properly wait for files to load on nodejs?
It is necessary to upload all files, and then send a message that all files have been uploaded.
function getFiles(arrContent, folder) {
arrContent.forEach((content, i, arr) => {
const file = fs.createWriteStream(`${inputFolder}/${folder}/${i}.jpg`);
const request = http.get(`${getUrl}${encodeURI(content.replace(/\s+/g,' ').trim())}`, (response) => {
response.pipe(file);
file.on('finish', () => {
file.close(); // close() is async, call cb after close completes.
}).on('error', (err) => { // Handle errors
fs.unlink(`${inputFolder}/${entities.encode(folder)}/${i}.jpg`);
console.log(`Error ${inputFolder}/${entities.encode(folder)}/${i}.jpg - not found!`);
});
});
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question