Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!