Node.js, process and threads question

Problem

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?

Problem courtesy of: never_had_a_name

Solution

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.

Solution courtesy of: nalply

View additional discussion.

Show your support

Clapping shows how much you appreciated Jamie Munro’s story.