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

109
Vistas
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 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