Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda