search

Home  >  Q&A  >  body text

A simple Hello world program creates multiple node instances

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粉496886646P粉496886646227 days ago455

reply all(1)I'll reply

  • P粉546257913

    P粉5462579132024-04-05 09:34:14

    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.

    reply
    0
  • Cancelreply