Several node instances being created for a simple Hello world program

38 Views Asked by At

I am very new to Javascript and NodeJS. I was running a simple helloworld programs as follows

Program 1

const durationInSeconds = 10;

console.log('Hello World');

setTimeout(() => {
  console.log(`Program has been running for ${durationInSeconds} seconds.`);
}, durationInSeconds * 1000);

When I ran the program , I was monitoring the processes using the htop command in linux. I noticed that the application was creating 7 node instances of the same application. Why is this happening? Why is it not creating only one node instance for a single simple application? I had this question because if I run a similar program in python I see only one instance of the python application running.

1

There are 1 best solutions below

0
Bharat D Bhadresha On BEST ANSWER

Nodejs is needs threads to do other tasks that are handled automatically for your by the V8 engine. Some of the things are

  • Interpreter
  • Event loop
  • Garbage collector
  • Blocking I/O executor and others...

Nodejs make programming easy by hiding these complexities from the programmer. If you need more control on these lower level 'stuff' then you can use C,C++ or other low level lanuages where you have to decide what should in which thread.