Reputation: 470
many question on stackoverflow and others website , some ones says NodeJS is Singlethread
and someone says NodeJS is Multithread
, and they have there own logic to be Singlethread
or Multithread
. But If a interviewer ask same question. what should I say. I am getting confusion here.
Upvotes: 1
Views: 4083
Reputation: 1403
The main event loop
in NodeJs is single-threaded
but most of the I/O
works run on separate threads.
You can make it multi-threaded
by creating child processes.
There is a npm module napajs
to create a multi-threaded javascript runtime.
However,the 10.5.0
release has announced multithreading in Node.js. The feature is still experimental
and likely to undergo extensive changes, but it does show the direction in which NodeJs is heading.
So stay tuned!!
Upvotes: 7
Reputation: 175078
NodeJS runs JavaScript in a single threaded environment. You get to use a single thread (barring the worker_threads
module, and spawning processes).
Under the scenes, NodeJS uses libuv
, which uses OS threads for the async I/O you get in the form of the event loop.
Upvotes: 3