'Express controller code doesn't seem to be running asynchronously [duplicate]

This is a much simplified version of an ExpressJS controller I have.

I put the sleep function in to test loading indicators on my front-end and I was very surprised that when calling this function twice simultaneously from the browser, instead of both taking 5 seconds they took a total of 10 seconds to complete.

function sleep(ms: number) {
    return new Promise(resolve => setTimeout(resolve, ms))
}


const get =  async (req: Request, res: Response, next: NextFunction) => {

    await sleep(5000)

    res.status(200).json({})


}

export default get

enter image description here

My understanding was that because I am using all asynchronous code the first one would wait for the timeout while other requests to the server continue to be served.

Whilst I don't use a sleep function everywhere else I do have lots of async code and I'm worried that each time I make a long DB call my API is being stopped from serving other requests, but this doesn't fit with my understanding of how Node/Express works, so am I just doing something wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source