Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
nodejs Promise.all() not working after promise process

I want to download images so I used Promise.

And my code snipped like that:

var download = function(uri, filename, callback) {
  request.head(uri, function(err, res, body) {
    /* console.log('content-type:', res.headers['content-type']);
    console.log('content-length:', res.headers['content-length']); */

    request(uri).pipe(fs.createWriteStream(filename + '.' + res.headers['content-type'].split('/')[1])).on('close', callback);
  });
};

var imagePaths = [];

for (const imageURL of imageURLs) {
  imagePaths.push(new Promise((resolve, reject) => {

    let filename = __dirname + '/../../../downloads/' + naming(6)
    download(imageURL, filename, function(data, err) {
      console.log("download image successful")
    });
  }))
}

Promise.all(imagePaths).then(() => {
  console.log("11")
  console.log(imagePaths)
});

And my output like that:

download image successful
download image successful
download image successful

And,

Promise.all(imagePaths).then(() => {
        console.log("11")
        console.log(imagePaths)

    });

not working.

Why Im not getting imagePaths? How can I solve this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!