Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda