Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
nodejs main thread and event loops, what is the difference between?

When http request hit into the Nodejs application the connect first received by Nodejs main thread (which is js main thread) and passed to event loop, if my understand is correct

The event loop is what allows Nodejs to perform non-blocking I/O operations, JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.

The above statement is from Nodejs official documentation, so my question where does the main thread lives?

out side the event loop or inside the event loop

is both different? Can someone give good pictures how Nodejs work internally, with graphical representation?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Main thread is the execution thread. As asked, it stays outside the event loop and will check for any events pertaining to the event loop.

If the even added to the event loop is synchronous and only needs some CPU operations, the main thread will take control directly and will execute the need.

If an asynchronous event is added to the event loop that is delegated to the worker threads available. Worker threads will perform the async operation(db/API/fs calls). Once the async part of the event is completed the event is again added to the event loop for the execution of the remaining synchronous part.

The worker threads are built over libUV and will spawn according to the main thread requirement. This reason makes Node.js more efficient while handling async calls and less preferred for CPU extensive operations.

Follow this for a more detailed explanation:
What function gets put into EventLoop in NodeJs and JS

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!