Changing the default port in Next.js

Gunschu Blog
Jun 8, 2022

--

So you just got started with Next js and started a new project , or cloned some project or boilerplate from github to check it out.

One issue I came across was that I already had one of my projects running on port 3000 and I couldn’t find a way to change the port!

This is because the port config is embedded into next.

By default they have chosen 3000.

To change the port you have to change your package.json to reflect the new port. The trick is a simple -p <PORT_NUMBER>

"scripts": {
"dev": "next dev -p 8080", // for dev server
"start": "next start -p 8080" // for prod server
},

Hopefully this helps someone!

--

--

Gunschu Blog

Gunschu is creating the world’s greatest coaching platform through groundbreaking tools, advice, knowledge and personal expertise.