Search code examples
node.jspm2

How to run 2 separate apps in PM2?


Right now I am using pm2 to run a node server app. I do that with pm2 start npm. This seems to be independent of the current directory.

I found some mentions online to use pm2 start npm --name "app_name" -- start. However, no matter what name I specify and directory I am inside, it always starts the same app.

Due to the nature of node, I don't run a single .js file and just type npm start in the current directory.

Edit: From my understanding, the problem seems to be that pm2 always starts /usr/bin/npm (Starting /usr/bin/npm in fork_mode (1 instance). So the --name flag doesn't matter much, ie. I can get a list of the same app with different names, and this app is node app A and sometimes node app B. I am kinda lost


Solution

  • What is happening is you have a PM2 app named npm, thus the confusion. You can list pm2 apps with pm2 ls

    First, remove it using :

    pm2 del npm
    

    Then, start a new app, naming it :

    pm2 start npm --name "app_name" -- start
    

    Then, the second app (in the other directory) with :

    pm2 start npm --name "app_name2" -- start