javascriptnode.jslinuxhtop

Several node instances being created for a simple Hello world program


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.


Solution

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

    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.