André Vermeulen André Vermeulen - 1 year ago 294
Node.js Question

PM2 environment variables caching

I am running PM2 on Ubuntu 16.04 and it seems that environment variables are being cached somehow. Is there an way of seeing which environment variables PM2 are using. The environment variables it can somehow see are not available in my terminal session anymore

echo $VAR_NAME

I created the environment variables like this:

export VAR_NAME=value

Removing the environment variable using:

unset VAR_NAME

doesn't work PM2 is stubbornly holding on to the environment variable - even after various restart & ssh sessions. Render me confused :-/

Is there a way of flushing the environment variables PM2 is using? Or at least seeing which environment variables it knows about?

Answer Source

You have to kill pm2 first.

pm2 kill

pm2 start app.js

PM2 preserves the environment variables it read upon starting, it does not reread their values every time.

I searched for it quickly, and found this issue on github:, and Unitech's answers confirm this.

In this particular comment:

Unitech says:

Yep this is normal in "cluster_mode". As pm2 wrap your code to his own context (and own variables) you get what was already there when launching pm2.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download