In this tip I will explain how we can deploy our Next.js Application in Production mode and also run that Application with PM2. If you don’t know about Next.js then in simple word it was client side framework like Angular or ember etc. But most important thing it have server side render support, Stay connect I am going to publish some more tutorial over Next.js soon.
Step 1. Open you package.json file and replace scripts with below code
"scripts": { "dev": "node server.js", "build": "next build", "start": "NODE_ENV=production node server.js" },
Step 2. Create your production build using below
npm run build
Step 3. Now once your build complete successfully run below command to run your Next.js with PM2
pm2 start npm --name "my_app_name" -- start
Hope this post help you.