Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

343
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda