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

111
Visualizações
Should Express JS be able to serve content while awaiting inside an existing request

I've seen something like this asked many times, but I never see a clear answer given.

Given an express server with a block like this:

var express = require('express');
var router = express.Router();    

app.use(async function(req, res, next){
    console.log("REQUEST DETECTED");
    await new Promise(r => setTimeout(r, 5000));
    next();
});

app.use('/', router.get('/', function(req, res, next) {
    // Serve a basic page
});

Consider this timeline

  1. Navigate a browser to the / route
  2. Console logs "REQUEST DETECTED"
  3. Open a new tab to the / route
  4. 5 seconds later, tab 1 displays the page content and the console outputs "REQUEST DETECTED" a second time.
  5. 5 seconds later, tab 2 displays the page content.

What I expected would be

  1. Navigate a browser to the / route
  2. Console logs "REQUEST DETECTED"
  3. Open a new tab to the / route
  4. Console logs "REQUEST DETECTED" a second time.
  5. 5 seconds later, both tabs display the page content.

Can Express not capitalize on time spent awaiting in order to process other requests? And just to be clear, the same thing happens when I await useful work like running a DB query. If one user requests a heavy query, the entire site hangs for every other user. Is there an alternative solution here?

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