Localhost, Ports, and Dev Servers

What localhost and ports are, how dev servers work, and how to fix common issues like port conflicts

When you run a dev server, it starts a web server on your own computer. You access it through localhost in your browser. This guide explains what that means, how ports work, and how to deal with common issues.

What is localhost?

localhost is your own computer. When you type http://localhost:3000 into a browser, you're telling it to connect to a server running on the same machine – not the internet.

Behind the scenes, localhost resolves to the IP address 127.0.0.1 (IPv4) or ::1 (IPv6). These are "loopback" addresses that always point back to your machine. Nothing you run on localhost is visible to the outside world by default.

What are ports?

A port is a numbered endpoint that identifies a specific service on your computer. Think of your computer's IP address as a building, and ports as apartment numbers – each service lives at its own port so they don't interfere with each other.

  • Port numbers range from 0 to 65535
  • Ports below 1024 are reserved for system services (HTTP on 80, HTTPS on 443, SSH on 22)
  • Dev servers typically use ports in the 3000-9000 range

When you see http://localhost:3000, the :3000 part is the port number.

Common dev server ports

Different tools have different default ports:

| Tool | Default Port | |---|---| | React (Create React App) | 3000 | | Next.js | 3000 | | Vite | 5173 | | Astro | 4321 | | Django | 8000 | | FastAPI (Uvicorn) | 8000 | | Express | 3000 (by convention) | | webpack-dev-server | 8080 |

Most dev servers will automatically try the next available port if their default is taken. Vite, for example, will try 5174 if 5173 is busy.

Port already in use

If you see an error like EADDRINUSE: address already in use :::3000 or port 3000 is already in use, another process is using that port. You need to either stop that process or use a different port.

Finding the process

macOS / Linux:

lsof -i :3000

This shows which process is using port 3000. Look at the PID column for the process ID.

To get just the PID:

lsof -t -i :3000

Windows (PowerShell):

Get-NetTCPConnection -LocalPort 3000

Look at the OwningProcess column for the PID.

Or in Command Prompt:

netstat -ano | findstr :3000

The last column is the PID.

Killing the process

macOS / Linux:

kill $(lsof -t -i :3000)

If that doesn't work, force it:

kill -9 $(lsof -t -i :3000)

Windows (PowerShell):

Stop-Process -Id <PID> -Force

Or in Command Prompt:

taskkill /PID <PID> /F

Replace <PID> with the actual process ID from the previous step.

Using a different port

Most dev servers let you specify a port:

  • Vite: vite --port 3001
  • Next.js: next dev -p 3001
  • React (CRA): PORT=3001 react-scripts start
  • Django: python manage.py runserver 3001
  • Express: change the port number in your code

Accessing your dev server from other devices

By default, localhost only works on the same computer. To access your dev server from a phone or another computer on the same Wi-Fi network, you need to bind to 0.0.0.0 instead of localhost.

  1. Start your dev server with the --host flag (most tools support this):
    vite --host
    
    or
    next dev -H 0.0.0.0
    
  2. Find your computer's local IP address:
    • macOS: System Settings > Wi-Fi > click your network > look for IP Address, or run ipconfig getifaddr en0 in Terminal
    • Windows: run ipconfig in PowerShell and look for the IPv4 address under your active adapter
    • Linux: run hostname -I or ip addr show
  3. On your other device, open a browser and go to http://192.168.x.x:3000 (replacing with your actual IP and port)

Both devices need to be on the same network. If it doesn't work, your firewall might be blocking the port.

localhost vs 127.0.0.1 vs 0.0.0.0

These look similar but behave differently:

  • localhost – a hostname that resolves to 127.0.0.1 (or ::1 for IPv6). Only accessible from your machine
  • 127.0.0.1 – the IPv4 loopback address. Same as localhost but skips DNS resolution. Only accessible from your machine
  • 0.0.0.0 – tells the server to listen on all network interfaces. This makes it accessible from other devices on your network, not just your machine

When a dev server says it's running on http://localhost:3000, you can also reach it at http://127.0.0.1:3000. But http://0.0.0.0:3000 in the browser doesn't work on all systems – use localhost or 127.0.0.1 instead.

HTTPS in local dev

Some browser APIs (geolocation, camera, service workers) require HTTPS, even on localhost. Most modern browsers treat localhost as a secure context by default, but if you need actual HTTPS certificates for local development, see our guide on setting up HTTPS for local dev.

Port forwarding for remote access

If you need someone outside your network to access your local dev server (for demos, testing, or webhooks), you'll need port forwarding or a tunneling tool. See our guide on port forwarding for the basics, or use a tool like ngrok or Cloudflare Tunnel for a simpler approach.

short

  • localhost = your own computer (127.0.0.1). Dev servers run here, only visible to you
  • Ports = numbered endpoints (:3000, :5173). Each service uses its own
  • Port in use? Find the process with lsof -i :3000 (Mac/Linux) or Get-NetTCPConnection -LocalPort 3000 (Windows), then kill it
  • Access from phone: start with --host flag and use your computer's local IP address

Frequently Asked Questions

Why do dev servers use such high port numbers?

Ports below 1024 are reserved for system services and typically require administrator privileges to use. Dev tools pick higher numbers (like 3000 or 5173) to avoid conflicts and permission issues.

Can two servers use the same port?

No. Only one process can listen on a given port at a time. If you try to start a second server on the same port, you'll get a "port already in use" error. Either stop the first server or use a different port.

Is localhost accessible from the internet?

No. Localhost is a loopback address that only points to your own machine. Nobody on the internet can reach your dev server unless you explicitly expose it through port forwarding or a tunneling service.

Why does my dev server show a different port than expected?

Most dev servers auto-increment the port if their default is already taken. If you expected port 3000 but got 3001, another process is likely using 3000. Check with lsof -i :3000 (Mac/Linux) or Get-NetTCPConnection -LocalPort 3000 (Windows).

What's the difference between stopping and killing a process?

A regular stop (like kill <PID> or Ctrl + C in the terminal) sends a graceful shutdown signal, letting the process clean up. Force killing (kill -9 or taskkill /F) terminates it immediately. Try the graceful approach first, and only force kill if the process is stuck.