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?
NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).
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 killNODE_ENV=production ./node_modules/.bin/pm2 start server.jsYou 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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With