I have this node app deployed and runs fine with NODE_ENV=production yarn start
.
I can demonize the app using
pm2 start npm -- start
but then it defaults to NODE_ENV=development
config.
And when I use
pm2 start npm -- start NODE_ENV=production
It still starts with development
config.
Also I tried passing the env using a process.yml
file
apps:
- script : index.js
watch: true
instances: 4
env :
NODE_ENV: production
but pm2 start npm -- start process.yml
still loads the development configs.
How can I fix this?
The reason you might be facing this is because you would have started pm2
with development
once. Now it will use that env until you kill
it. Following these steps should help
./node_modules/.bin/pm2 kill
NODE_ENV=production ./node_modules/.bin/pm2 start server.js
You can also use --update-env
. From the official docs
By default we want that PM2 doesn’t change process environment while restarting or reloading so they are immutable. If you want to update them, you must use --update-env :