Search code examples
pm2nuxt3.js

Passing env variables from PM2 to my Nuxt 3 App


I am using PM2 with a ecosystem.config.js config file to start my app. I am trying to pass env variables to my Nuxt 3 app, but they don't seem to be accessible from my app. This is my ecosystem.config.js:

module.exports = {
  apps: [
    {
      name: 'frontend',
      exec_mode: 'cluster',
      instances: 'max',
      script: './frontend/server/index.mjs',
      env: {
        NODE_ENV: 'production',
        NUXT_HOST: '10.0.0.49',
        NUXT_PORT: '3500',
        NUXT_BASE_URL: 'http://10.0.0.49:3500',
      },
    },
  ],
};

What am I doing wrong? 🤔

pm2 env 1 shows that all my env vars are there. However, in my Nuxt 3 App they are undefined.


Solution

  • Well... turns out the env variables were present, but the correct names are HOST instead of NUXT_HOST and PORT instead of NUXT_PORT 🤦‍♂️