I am new to nodejs. After reading few articles I understood that nodejs is single threaded. I am totally surprised that how nodejs handles multiple client requests. For example, if one user hit node server, other user request has to wait until it responds to first client request. Please help me to understand how node works in single threaded environment.
Asked
Active
Viewed 2,054 times
1
-
My analogy with phone dispatcher: http://stackoverflow.com/questions/17822943/how-does-the-node-js-event-loop-work-with-async-commands/17823813#17823813 – Andrey Sidorov Jan 07 '14 at 13:51
-
There are many resources that detail this topic already on the Internet. – WiredPrairie Jan 07 '14 at 14:13
-
Thanks guys, I tried google first but unfortunately I did get a clear picture so decided to put it on here. – Upendra Dev Singh Jan 08 '14 at 12:07
1 Answers
1
When people say Node is single threaded what they mean is that there is only one thread of JavaScript code being executed. But that does not mean that there aren't other thread executing. For example, most I/O in Node is asynchronous by default and that spins up other threads.
I've posted a diagram in this question Thread in an event-driven vs non-event driven web server that shows how these threads work and for the most part my assumption #4 in that question seems to hold true.

Community
- 1
- 1

Hector Correa
- 26,290
- 8
- 57
- 73