run pm2 in specific port and using cluster mode

Viewed 497

I have nuxt js application now its running in fork mode.

I have tried using this ecosystem file but not working.

module.exports = {
    apps : [{
        name      : 'MyAppName', // App name that shows in `pm2 ls`
        exec_mode : 'cluster', // enables clustering
        instances : 'max', // or an integer
        port: 1234,
        script    : './node_modules/nuxt/bin/nuxt-start', // The magic key
    }]
};

Is it possible to run pm2 using cluster mode in specific port?

1 Answers

Combining pm2's docs with Nuxt.js's it seems that adding env variables to your ecosystem file should accomplish what you're asking:

apps : [{
        name      : 'MyAppName', // App name that shows in `pm2 ls`
        exec_mode : 'cluster', // enables clustering
        instances : 'max', // or an integer
        env: {
          NUXT_PORT: "1234"
        },
        env_production: {
          NUXT_PORT: "1234"
        },
        script    : './node_modules/nuxt/bin/nuxt-start', // The magic key
    }]

https://nuxtjs.org/faq/host-port/#with-nuxt_host-and-nuxt_port-env-variables

https://pm2.keymetrics.io/docs/usage/application-declaration/#generate-configuration

Related