A simple Hello world program creates multiple node instances
P粉496886646
P粉496886646 2024-04-04 11:03:22
0
1
525

I am very new to Javascript and NodeJS. I'm running a simple helloworld program as follows

plan 1

const durationInSeconds = 10;

console.log('Hello World');

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

When I run this program, I am using the htop command in Linux to monitor the process. I noticed that the application was creating 7 node instances of the same application. Why does this happen? Why doesn't it create just one node instance for a single simple application? I have this problem because if I run a similar program in python, I only see one instance of the python application running.

P粉496886646
P粉496886646

reply all(1)
P粉546257913

Nodejs requires threads to perform other tasks that the V8 engine handles automatically. Some of these things are

  • Interpreters
  • Event Loop
  • Garbage Collector
  • Blocking I/O executor and others...

Nodejs makes programming easy by hiding these complexities from programmers. If you need more control over this lower level "stuff" then you use C, C++ or other low level languages ​​and you have to decide what should go in which thread.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template