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

144
Views
Terminating multiple node processes start from NPM run script

I've got the following for spawning multiple node processes when user npm starts:

"scripts": {
    "start": "node calculator.addition/index.js & node calculator.division/index.js & node calculator.multiply/index.js & node calculator.subtract/index.js &"
}

This works fine to start multiple node processes but when I command/ctrl c, the processes are still alive. Any ideas how I can correctly exit these processes?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I suggest you run it with a node_modlue called concurrently that way all processes will run at the same time and it will stop once you tell it to stop.

scripts: {
  "start": "concurrently --raw --kill-others \"npm run addition\" \"npm run node2\"",
  "addition": "node calculator.addition/index.js",
  "division": "node calculator.division/index.js",
  ...etc
}
over 4 years ago · Santiago Trujillo Report

0

You can also use pm2 to manage your services lifecycle):

pm2 start node calculator.addition/index.js --name addition

This way you can stop all processes with :

pm2 stop all

Your scripts section would look like :

"scripts": {
    "start": "pm2 stop -s addition division;pm2 delete -s addition division; pm2 start node calculator.addition/index.js -n addition; pm2 start node calculator.division/index.js -n division"
}
over 4 years ago · Santiago Trujillo 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!