Table of Contents
By default, when you run
npm run dev, it will start the Next.js app in port 3000.
There can be times when port 3000 is used by another application or you have a requirement to start the server in another port.
We will see how to achieve it in this article.
Creating a Next.js Project
First, create a new Next.js project using the following command:
Updating the port
Now let's say you want to change the port to 8090. You can open the
package.json and update the
dev script as follows:
1"dev": "next dev -p 8090",
Now if you run
npm run dev, you should be able to access the app at http://localhost:8090.
Setting the port for production build
If you want to run the project in a different port after it is built (after running
npm run build),
you can do so by updating the
1"start": "next start -p 8090",
Now you can run
npm start to see the page served at port 8090.
Do follow me on twitter where I post developer insights more often!
Leave a Comment