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

350
Visualizações
How do you execute code once data from an http request is received?

I'm new to web development and have been using a node.js web server running express as a backend for an app I'm working on for my school. One of the things this server needs to do is to query the school's database, receive information, and return that to the user. While I've gotten it to work, I'm receiving a delay of almost 2 seconds from the start to the end of the request. This is because the server must make 2 requests to get the information it needs. What I'm trying to figure out is how to make both of them run asynchronously and preforming tasks once the information is received. Attached is some demo code showing what I've got so far.

   axios
        .get(
            `https://schoolserver.com/classes`,
            config
        )
        .then((res) => {
            classes = res.data.value;
            axios
                .get(
                    `https://schoolserver.com/meetings`,
                    config
                )
                .then((res) => {
                    meetings = res.data.value;
                    }
                    response.send(classes, meetings);
                })
                .catch((err) => {
                    console.log(err);
                });
        })
        .catch((err) => {
            console.log(err);
        });

As you can see I have 2 axios requests nested within each other which creates unwanted delay. I want a solution where both requests are done independently and then code is executed once the data is received. If there are any solutions please reach out.

about 4 years ago · Juan Pablo Isaza
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