0

I have few Nodejs servers, they are small servers and each one of them is stored in a separate folder. And all the folders are stored in one root folder. Every time i want to run the servers i have to go through each one of them and type

nodemon *name*.

This is becoming tiresome, especially that the number of servers is growing. is there any tool or a script i could use to run all the servers in one command?? Basically, how can i run all the servers in one command or a script?

Niki Hasel
  • 87
  • 1
  • 1
  • 4

3 Answers3

1

With NPM. Write this in package.json :

{
  "name": "project-name",
  "version": "1.0.0",
  "scripts": {
    "start": "nodemon server1.js | nodemon server2.js | nodemon server3.js"
  }
}

Then you only need to execute npm start.

Also see this post

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
1

PM2 is a great answer for this.

pm2 start app.js -i 4 (or max will take up all available cores)

You also get great benefits such as automatic restarts, log aggregation and load balancing.

Simon Poole
  • 493
  • 1
  • 6
  • 15
0

Use pm2

If you use Linux

#!/bin/bash 

pm2 start << Path to User Server>> 
pm2 start << Path to User Server>> 

pm2 logs 

You can save

pm2 save 

pm2 list 

pm2 stop 
Alex Michailidis
  • 4,078
  • 1
  • 16
  • 35
Amila Sampath
  • 655
  • 4
  • 11
  • 28