Pm2 application version not available

Viewed 2625

I have an Express server whose package.json contains bin section to create a link to run the app.

I want to run the server using pm2 and I generated the ecosystem file as follows:

module.exports = {
  apps : [{
    name: 'myServer',
    script: 'myserver',
    max_memory_restart: '500M',
    env: {
      NODE_ENV: 'development',
      USER_CONFIG_FILE: '/etc/myserver/myserver-config.json'
    },
    env_production: {
      NODE_ENV: 'production'
    },
    disable_logs: true
  }]
};

The ecosystem file is in the home folder of my user (because it will contain all apps) and when I run pm2 start the server correctly starts up, but the version column of the app table says N/A.

I also tried to add to ecosystem file the cwd field set to the directory where the server is installed.

pm2 shows app version correctly only if I run pm2 start main.js from inside the server installation folder.

Is there any way to tell pm2 how to extract app version when launched from arbitrary folder?

1 Answers

I found a workaround avoiding the use of the link created through bin section. I used ecosystem field cwd to point folder containing package.json and set script with the name of main main script.

module.exports = {
  apps : [{
    name: 'myServer',
    cwd: '/path/to/app/',
    script: 'index.js',
    max_memory_restart: '500M',
    env: {
      NODE_ENV: 'development',
      USER_CONFIG_FILE: '/etc/myserver/myserver-config.json'
    },
    env_production: {
      NODE_ENV: 'production'
    },
    disable_logs: true
  }]

};

Related