Skip to content

How to change a Next.js app port

Learn how to change the port that Next.js runs on in development mode

I've been asked how to change the HTTP port of an app built using Next.js, when you are running it locally. By default the port is 3000, but that's a commonly used port and perhaps you have another service running on it.

How can you change it?

The answer is in the package.json file stored in the Next.js app main folder.

By default the file content is this:

  "name": "learn-starter",
  "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"

Note: the exact packages numbers will differ in your case, as they get updated

The thing you need to change is the scripts part.


"dev": "next dev",


"dev": "next dev -p 3001"

to start Next.js on port 3001 instead of 3000.

Now when you run npm run dev, the command used to start the development server locally, you will see it start on port 3001:

→ Download my free Next.js Handbook!



You might be interested in those things I do:

  • Learn to code in THE VALLEY OF CODE, your your web development manual
  • Find a ton of Web Development projects to learn modern tech stacks in practice in THE VALLEY OF CODE PRO
  • I wrote 16 books for beginner software developers, DOWNLOAD THEM NOW
  • Every year I organize a hands-on cohort course coding BOOTCAMP to teach you how to build a complex, modern Web Application in practice (next edition February-March-April-May 2024)
  • Learn how to start a solopreneur business on the Internet with SOLO LAB (next edition in 2024)
  • Find me on X

Related posts that talk about next: