How to change a port number in Next.js app

How to change a port number in Next.js app

In this post we will give you information about How to change a port number in Next.js app. Hear we will give you detail about How to change a port number in Next.js appAnd how to use it also give you demo for it if it is necessary.

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

  1. Open the next app in your favorite code editor.

  2. 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.

  1. 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

Hope this code and post will helped you for implement How to change a port number in Next.js app. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US