Use the PM2 architecture.config.js file as follows:
module.exports = { apps : [{ name: "app", script: "./app.js", merge_logs: true, max_restarts": 50, //Here you can define your max restarts instances: "max", max_memory_restart: "200M", env: { NODE_ENV: "development", }, env_production: { NODE_ENV: "production", } }] }
Start your server by running the command:
pm2 start ecosystem.config.js //uses variables from 'env' pm2 start ecosystem.config.js
See the link below for more details:
PM2 Runtime | Guide | Ecosystem file
source share