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

105
Views
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 answers
Answer question

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 Report

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 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!