localhost:3001 (and 3002): Why the Port Changed

Seeing localhost:3001 almost always means port 3000 was busy when your dev server started, so Next.js or Create React App took the next free number. A third server lands on 3002. Nothing is broken, but logins, API calls and bookmarks that expect 3000 can fail until you free or pin the port.

How common tools react when 3000 is taken
ToolWhat it doesPin the port with
Next.js (next dev)Warns and uses 3001next dev -p 3000
Create React AppAsks to run on another portPORT=3000 in .env
Express or plain NodeCrashes with EADDRINUSEapp.listen(process.env.PORT || 3001)
Remix / React Router devPicks a free port and prints it--port flag

Updated

Port 3001 is rarely anyone's first choice. It shows up because an earlier copy of the same project, a second app in a monorepo, or a backend API already took 3000. Many teams also choose 3001 on purpose for the API so the frontend can keep 3000.

Free port 3000 and pin it

Find and stop the process on 3000

The first two lines are for Mac and Linux, the last two for Windows Command Prompt.

lsof -i :3000
kill <PID>

netstat -ano | findstr :3000
taskkill /PID <PID> /F

Pin the port in package.json

With a fixed port, a busy 3000 becomes a clear error instead of a silent move.

"scripts": {
  "dev": "next dev -p 3000",
  "api": "PORT=3001 node server.js"
}

When 3001 breaks things that worked on 3000

Cookies are scoped by host, not port, yet CORS allow lists and auth callbacks are scoped by full origin. An app that moved to 3001 can therefore load fine and still fail every login or API request.

Fixing the root cause beats adding 3001 everywhere: free 3000, or decide that the port is fixed and make the tool fail loudly when it is taken.

People who only want a business site live, without juggling dev servers on numbered ports, can build it in the browser with We.Inc instead.

How it works

  1. Read the dev server output and note the exact port it reports.
  2. Find the process still holding 3000 with lsof or netstat.
  3. Close that terminal or kill the stale process if you did not mean to run it.
  4. Restart your server and confirm it is back on the port your config expects.

Tips

  • A frontend on 3000 and an API on 3001 is a deliberate, common split. Store the API address in an environment variable rather than in code.
  • OAuth providers reject callbacks from 3001 when only 3000 is registered, which shows up as a redirect_uri mismatch rather than a port error.
  • VS Code can leave a dev server running in a hidden terminal after a window reload, which is a frequent reason 3000 stays taken.
  • Turborepo and similar monorepo runners start several apps at once, so give each one a fixed port in its own package script.

Frequently asked questions

Why is my Next.js app running on localhost:3001?

Something else was listening on 3000 when you ran next dev, so Next.js chose 3001 and printed a warning. Stop the other process or start with next dev -p 3000 after freeing it.

What is localhost:3002?

It is the next port after 3001. When two servers already hold 3000 and 3001, a third Node dev server falls through to 3002. Check for duplicate terminals before anything else.

How do I see what is using port 3000?

Run lsof -i :3000 on Mac or Linux, or netstat -ano | findstr :3000 on Windows. Both show the process ID, which you can stop with kill or taskkill.

Should my API run on 3001?

It is a reasonable convention when the frontend owns 3000. Keep it consistent in every developer's .env file and in the frontend's proxy or fetch base URL.

Related: localhost:3000, localhost refused to connect, localhost:4000, CORS explained.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

Product

Who It's For

Features

Resources

Company

View Sitemap