Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda