'Is it possible to have multiple different pm2 instances running at the same time?

I am just wondering if I can seperate my pm2 instances. For example, let's say I have one ecosystem file that I start in one terminal, and then I go ahead and start another ecosystem file in another terminal. Both processes seem to merge and start outputting the same logs. Becomes real annoying real quick. Is there a way to have them seperate?



Solution 1:[1]

PM2 uses the .pm2 folder by default to place its logs and .pid file. PM2 uses the PM2_HOME environment variable to know where this folder is. I uncovered this when I was moving the folder to a larger drive and ended up with a new instance when I checked on the apps it was monitoring. As stated in the docs about running multiple PM2 instances, you can run multiple PM2 instance simply by specifying a different folder for each:

PM2_HOME='.pm2' pm2 start echo.js --name="echo-node-1"
PM2_HOME='.pm3' pm2 start echo.js --name="echo-node-2"

Keep in mind that to run any PM2 commands, you'll have to prefix with the proper PM2_HOME:

PM2_HOME='.pm2' pm2 list
PM2_HOME='.pm3' pm2 list

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wwwslinger