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

106
Visualizações
Why do we refactor Node.js code in different files

I have a question. I am a beginner in node.js and I know that we refactor our server code into different files(like index.js, server.js, routes.js, etc.), to make our codebase more manageable and the code more readable.

However my senior informed me that we are splitting our code in different files so that node js can spawn a separate process for each file and several concurrent pieces of code are running at once.

This logic was a bit difficult to digest for me and I think that nodejs is single threaded, and we can use setTimeout/promises to send our async tasks to the Event queue. My understanding was that once we use a require statement, the code is directly imported to where we are importing it from.

Is my understanding wrong?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

First of all, NodeJS is not single threaded as many seems to think.
It has 4 threads by default which are separated for different tasks such as working with I/O.

Our "main" javascript code works in one of these threads.

By our own purpose we can spawn more threads with help of worker_thread module.
These spawned threads requires some code to execute.
We have to give them the code by passing the path to file (or URL) into constructor.

I want to believe that my explanation is as clear as it could be :P

about 4 years ago · Juan Pablo Isaza Relatório

0

First of all, NodeJS is not single threaded as many seems to think.
It has 4 threads by default which are separated for different tasks such as working with I/O.

Our "main" javascript code works in one of these threads.

By our own purpose we can spawn more threads with help of worker_thread module.
These spawned threads requires some code to execute.
We have to give them the code by passing the path to file (or URL) into constructor.

I want to believe that my explanation is as clear as it could be :P

about 4 years ago · Juan Pablo Isaza 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