0

Let's say I have this route:

app.get('/sayHello', (req, res) => {
  res.send('Hello User!')
})

If the server get 200 simultaneous requests (meaning, at the same exact moment) to this route,

how does Node.js decide which should be served first, second... etc.?

Jaher
  • 1
  • 1
  • 3
    Does this answer your question? [How does Node.js handle simultaneous requests with one thread?](https://stackoverflow.com/questions/29220878/how-does-node-js-handle-simultaneous-requests-with-one-thread) – Heartbit Nov 09 '20 at 18:27
  • From what I read there, my route above will get his own send and receive queue on the OS that runs Node, and Node will execute the 200 requests by the order of that queue? – Jaher Nov 09 '20 at 18:37
  • the order is not important since the `event loop` try to resolve the result as response if the request has been finished and the callback has a return – Heartbit Nov 09 '20 at 18:44
  • Think about that like a queue of pepole with just one reception to handle their requests but `nodejs` uses more receptions for handling their requests – Heartbit Nov 09 '20 at 18:48
  • And these extra receptions are new threads? which share the CPU power with each other? – Jaher Nov 09 '20 at 18:57
  • No, `nodejs` is single thread, the event loop do so if is not blocked with a high cpu computation – Heartbit Nov 09 '20 at 19:10
  • But the extra receptions RUN in the event loop, no? I – Jaher Nov 09 '20 at 19:22
  • Read more details here https://stackoverflow.com/questions/34855352/how-in-general-does-node-js-handle-10-000-concurrent-requests – Heartbit Nov 09 '20 at 20:23
  • Thank you for all the answers – Jaher Nov 09 '20 at 21:05

0 Answers0