never_had_a_name
never_had_a_name

Reputation: 93156

Node.js, process and threads question

Does process have at least one thread running?

If so, then the Node.js will by default have 1 main thread and 1 event loop thread running?

Upvotes: 2

Views: 584

Answers (1)

nalply
nalply

Reputation: 28717

No, node.js runs only with one thread. There is no "main thread" and "event loop thread". First run the initialzation code then the event loop is entered. The event loop runs the event and timeout handlers. Exactly as in the browser: first run the initialization code in the <script> tags, then the handlers.

Except the workers, but also here it is the same as in the browser (HTML5 workers). A worker thread or process is started separately to offload long-running calculations and a handler is run when the worker finished its task.

Upvotes: 2

Related Questions