Is NodeJs really single threaded?
theRealJS
Last updated on
Your thoughts?
Share your thoughts
No. NodeJs is not single threaded. The NodeJs event loop operates on a single thread yes, but the async blocking operations are delegated to separate worker threads. These threads notify the main thread when they are done processing.
While you can argue that NodeJs event loop is single threaded, it would be a lie to say that NodeJs doesn't use anymore than one thread. Depending on what kind of blocking i/o you are dealing with, multiple thread pools can be spun up to handle activity asynchronously. This is what allows the event loop to remain "single threaded"....a bit ironic if you ask me.
No.
Yes and no. The NodeJs event loop is a single thread. This is true.
But when this single thread encounters blocking i/o, it will delegate the task to a separate pool of worker threads. These worker threads are handled by underlying C libraries or browser extensions. Since these processes aren't directly connected to the NodeJs event loop, they are technically not "part of node".
But this question results in a lot of "smoke and mirrors" statements.
At the end of the day, if you use NodeJs you are probably going to use more than one thread...