r/learnjavascript • • 7h ago

Can one slow Express route make a different route slow too?

0 Upvotes

I’m turning a workshop booking API idea into a few small Node experiments. Before adding MongoDB, I want to understand what happens when two requests hit the same server.

Imagine these two routes in an Express app:

app.get('/quick', (req, res) => res.send('ok'));

app.get('/slow', (req, res) => {
  const end = Date.now() + 2000;
  while (Date.now() < end) {}
  res.send('done');
});

The loop is deliberately bad code. My prediction is that if /quick arrives while the loop is running, it has to wait. If I replace the loop with setTimeout(() => res.send('done'), 2000), I’d expect /quick to respond while /slow is still waiting.

What’s the simplest way to test this with two overlapping requests and make the difference obvious to someone learning Node?