PM2 for NextJS - ecosystem file
-
File: ecosystem.config.js
module.exports = { apps: [ { name: 'service-name-3000', cwd: '/var/www/test', script: 'node_modules/next/dist/bin/next start --port 3000', args: '', watch: false, instances: '1', // Or a number of instances // ignore_watch: ['database'], autorestart: true, env: { PORT: 3000, ENV_PATH: "./.env.local", } } ] };
module.exports = { apps: [ { name: 'NextAppName', exec_mode: 'cluster', instances: '1', // Or a number of instances script: 'node_modules/next/dist/bin/next', args: 'start -p 5000', env_local: { APP_ENV: 'local' // APP_ENV=local }, env_development: { APP_ENV: 'dev' // APP_ENV=dev }, env_production: { APP_ENV: 'prod' // APP_ENV=prod } } ] }
Ref: https://dykraf.com/blog/deploying-nextjs-web-application-with-pm2