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 3000
.
Changing the Port number
-
Open the next app in your favorite code editor.
-
Navigate to the
package.json
file and add the-p
flag with your desired port number to the following command.
"dev": "next dev -p 5000",
Here I added a port number 5000
.
- Now, run the development server using
npm run dev
command your app will start on the port number you specified in step 2.
➜ nextjs-blog git:(master) ✗ npm run dev
> learn-starter@0.1.0 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