How to change the development server port in Next.js

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.
Introduction
When running up the Next.js application locally, by default the application will run on port 3000 and that's a very commonly used port.
Now the question arises, how to change the server port?
Changing the port
The answer to the question is package.json inside the Next.js application folder.
By default, this is how your package.json looks,
{
"name": "change-port-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "9.3.5",
"react": "16.13.1",
"react-dom": "16.13.1"
}
}
The thing you need to change is in scripts,
"dev": "next dev",
to:
"dev": "next dev -p 2000"
Now the port has changed to 3000 --> 2000
Conclusion
I hope this article was helpful to you! Thank you for reading!
Let’s connect
If you found my content helpful and would like to thank me, feel free to Buy me a coffee :)
Have a great day!




