← coderrocketfuel.com

Run a Next.js Application on a Different Port Number

How can you run a Next.js application on a specific port number?

By default, Next.js runs on the localhost:3000 port.

To change that, open the package.json file for your application and update the "scripts" section to this:

"scripts": {
  "dev": "next dev -p 8080",
  "build": "next build",
  "start": "next start -p 8080"
},

The -p flag tells Next.js to run the application on port 8080. In the code above, your application will run on port 8080 in both development mode (npm run dev) and production mode (npm start).

Change 8080 to whatever port number you want to use instead.

You'll need to restart your application to observe the port number change.

Thanks for reading and happy coding!