I am writing NODE_ENV=production pm2 start app
to run the node environment into production mode. But somehow when I extract the value with app.get('env')
it gives me development value only. So what should be inserted to run node environment into production mode ?
By default we want that PM2 doesn’t change process environment while restarting or reloading. So, In order to change the ENV value of a process just stopping and starting won't work.
You have to either DELETE
the process and start again(which I mainly do because when I change envs there are some major changes happening inside, so this method works for me)
pm2 delete app
NODE_ENV=prod pm2 start app
Or, From the Doc "If you want to update them [While restarting/reloading a process], you must use --update-env
":
You want to inject a new environment variable to a process (for example DEBUG): Use
DEBUG=* pm2 reload myapp --update-env