node.js – express concurent requests with async/await

From what I understand, in express/node.js, requests are processed in a concurrent way, even when using async/await.

I have made some tests, and I can’t understand why server is waiting for the current request to finish, before treating the next one.

This is my code:

const express = require('express');
const app = express();

// Simulate a long async operation with a non-blocking wait
async function longAsyncOperation() {
  return new Promise(resolve => setTimeout(resolve, 10000));  // 10 seconds delay
}

app.get('*', async function (req, res) {
  console.log("route called");
  try {
    await longAsyncOperation();  // Simulate a long async operation
    res.send("route resolved"); 
  } catch (error) {
    res.send("route rejected");
  }
})

app.listen(8001, () => {
  console.log("Server running on port 8001");
})

Read more here: Source link