Hkm Sadek
Hkm Sadek

Reputation: 3209

Start nextjs project in production with a specific port

I have two nextjs projects and one running on default 3000. My project was running smoothly until I upgraded the server and restarted all pm2.. For the second project, I am trying to assign port like this in package.json file

"start": "next start -p 8080" then using pm2 start ecosystem.config.js but I see it runs on port 3000... How can I make it run on a specified port..

Upvotes: 1

Views: 957

Answers (1)

Yahya Aghdam
Yahya Aghdam

Reputation: 578

Create a PM2 configuration file for your Next.js app. You can create a file named pm2.config.js and add the following code:

module.exports = {
  apps: [
    {
      name: "next-app",
      script: "npm",
      args: "run start",
      env: {
        NODE_ENV: "production",
        PORT: 8000, // Change this to the port you want to use
      },
    },
  ],
};

Start the app using PM2 by running the following command in your app directory:

pm2 start pm2.config.js

Upvotes: 1

Related Questions