2

I had read in Node.js processing model that node simply accept the request using event loop and give the work to c++ working threads which are performing the async operations.

I also read that :

  • Node is evented not single threaded.
  • In node all the things run parallel except your code.
  • In node if you use settimeout function nothing will be working in that time.

I have done some research but not be able to reach to a conclusion. My question is:

  • If node is using c++ working threads how can you say it is single threaded?
  • how everything is parallel except our code?
  • Is settimeout thing is true or not?
Pankaj Jindal
  • 175
  • 1
  • 2
  • 10
  • check out this article http://rickgaribay.net/archive/2012/01/28/node-is-not-single-threaded.aspx – Ellery Jun 18 '14 at 05:19
  • JavaScript execution in Node is single-threaded, but Node does use multiple threads (script execution is only part of the entire platform). The others are reserved for native code to implement asynchronous APIs. – Jonathan Lonowski Jun 18 '14 at 05:22

1 Answers1

2

Node.js naked runs on a single process, on a single thread.

But there is a webworker extension that allows to run more than one thread:

https://www.npmjs.org/package/webworker-threads

For spawning multiple processes check out the cluster module

(See a nice updated tutorial here: http://blog.carbonfive.com/2014/02/28/taking-advantage-of-multi-processor-environments-in-node-js/)

And also the most updated answers on the topic:

What is Node.js?

https://stackoverflow.com/a/8685968/1060686

Community
  • 1
  • 1
NotGaeL
  • 8,344
  • 5
  • 40
  • 70
  • All the answers related to node are almost 2 years old. I want some fresh opinion. – Pankaj Jindal Jun 18 '14 at 05:37
  • 1
    Well it seems for NodeJS the answer is still the same. If you don't care about using a fork, based on its reviews JXcore seems to be a pretty good one: http://jxcore.com/home/ (I haven't tried it, though) – NotGaeL Jun 18 '14 at 05:44
  • 1
    @PankajJindal Node hasn't changed that much of its foundations within the 2 years. – Jonathan Lonowski Jun 18 '14 at 05:44