Search code examples
node.jsexpresspm2

Passing environment variables to node.js using pm2


I am trying to pass some arguments to my Express application which is run by pm2. There wasn't any hint in their documentation to do so, but apparently it's possible to pass some EV to your node application like SOME_STUFF=xxx pm2 start app.js.


Solution

  • It's actually possible and I'm pretty sure it was in PM2's documentation some time ago.

    Anyways, that's what you need to do:

    pm2 start app.js -- -some_stuff xxx
    

    Basically, add -- and then you can add your own app parameters.

    Managed to find the source, it was hidden quite well: http://pm2.keymetrics.io/docs/usage/quick-start/#42-ways-of-starting-processes