How to change a port number in Next.js app
In this tutorial, we are going to learn how to change a default port number in the next.js app.
Note: If we create a new next app using the
create-next-app cli, by default the app runs on the port
Changing the Port number
Open the next app in your favorite code editor.
Navigate to the
package.jsonfile and add the
-pflag with your desired port number to the following command.
"dev": "next dev -p 5000",
Here I added a port number
- Now, run the development server using
npm run devcommand your app will start on the port number you specified in step 2.
➜ nextjs-blog git:(master) ✗ npm run dev > firstname.lastname@example.org dev /Users/saigowtham/Desktop/nextjs-blog > next dev -p 5000 [ wait ] starting the development server ... [ info ] waiting on http://localhost:5000 ... Browserslist: caniuse-lite is outdated. Please run next command `npm update` [ ready ] compiled successfully - ready on http://localhost:5000
If you want to change a port number temporarily, then you can use the following command.
npm run dev -- --p 5002