PM2 run next.js project

To run Next.js project using pm2 use the following command

# for development
pm2 start npm --name "project-name" -- run dev

# for production
npm run build
pm2 start npm --name "project-name" -- start

The default port is 3000 , to change it add -p 'port number' in package.json :

"dev": "next dev -p 3007"

or in the command line

npm run dev -- -p 3007