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

114
Views
Node.js Response.send returning no data before function finishes

Can someone explain to me why the function below is returning before retrieve_s3_file() finishes?

The client receives no data from response.send below. The data returned from retrieve_s3_file() is correct (based on console output), but a response with no data is sent back to client first.

app.post("/getJobStatus", function(request, response){
    var guid = request.body.job_id;
    var to_do_list = [];
    var data_list = [];
    var completed_list = [];

axios.get(job_queue_url + "/list?guid=" + guid)
        .then(function (res){
          console.log("Response from API gateway : ");
          console.log(res.data);
          files = res.data;
          for (let i = 0; i < files.length; i++)
          {
            if (files[i] in completed_list) {continue}
            else {
              to_do_list.push(files[i]);
              completed_list.push(files[i]);
            }
          }
          response.send(retrieve_s3_file(to_do_list, guid));
        })
        .catch(function (error){
          console.log(error);
        });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If retrieve_s3_files is asynchronous you will need to wait for the promise to resolve before you can use the value. You can change that last line to something like this:

retrieve_s3_file(to_do_list, guid).then(val => {
    response.send(val);
}).catch(error => {
    console.log(error)
});

I have added the .catch method so you can gracefully handle any errors that occur while interacting with s3.

about 4 years ago · Santiago Trujillo Report
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!