All posts
4 min read

What Is an IP Address and a Port? localhost:3000 Explained

Every network connection goes to an address and a port — the building and the apartment number. What IP addresses and ports are, the common port numbers, what 0.0.0.0 means, why 'address already in use' happens, and why your app works on your laptop but not on the server.

getting startedinfrastructuredebuggingbeginner

localhost:3000. 127.0.0.1:5432. 0.0.0.0:8080. EADDRINUSE. If you run apps, you'll see addresses and ports constantly. They're simple once you have the right picture.

The picture: buildings and apartments

  • An IP address is the street address of a building — which computer.
  • A port is the apartment number — which program on that computer.

One computer runs many programs that talk over the network — your web app, a database, a cache. They all share the computer's address, so each listens on its own port. A connection needs both: address:port.

IP addresses

An IP address identifies a device on a network.

  • IPv4 looks like 203.0.113.42 — four numbers from 0 to 255. There are only about four billion possible, which the internet ran out of long ago.
  • IPv6 looks like 2001:db8::1 — much longer, with vastly more addresses.

Some addresses are special:

Address Meaning
127.0.0.1 (and ::1) This computer. Also known as localhost.
0.0.0.0 When a server listens on it: "every network interface on this machine."
192.168.x.x, 10.x.x.x, 172.16–31.x.x Private addresses — used inside home and office networks, not reachable from the internet.
Anything else Usually public — reachable across the internet.

Domain names exist so people don't have to remember these. DNS turns yourapp.com into an IP address. (DNS Records Explained.)

Ports

A port is a number from 0 to 65535. A program listens on a port; clients connect to it.

Common ones worth recognising:

Port Usually
22 SSH (SSH Keys Explained)
80 HTTP
443 HTTPS
3000 Node.js / Next.js dev servers
5173 Vite dev server
8000 / 8080 Python dev servers, alternative HTTP
5432 PostgreSQL
3306 MySQL
6379 Redis
27017 MongoDB

Browsers hide ports 80 and 443 because they're the defaults for http and https. (Anatomy of a URL.)

localhost:3000

Put the two together: localhost:3000 means "the program listening on port 3000, on this computer." That's your app's development server. Nobody else can reach it, because localhost always means the machine you're on. (What Is localhost?.)

"Address already in use"

Error: listen EADDRINUSE: address already in use :::3000

Only one program can listen on a given port at a time. Something is already on 3000 — usually an old copy of your app that didn't shut down, or another project.

Find and stop it:

# macOS / Linux
lsof -i :3000
kill <PID>

# Windows (PowerShell)
Get-NetTCPConnection -LocalPort 3000 | Select-Object OwningProcess
Stop-Process -Id <PID>

Or just run your app on another port, often with PORT=3001 npm run dev.

127.0.0.1 vs 0.0.0.0: the classic deployment bug

When a program starts listening, it chooses which address to listen on:

  • 127.0.0.1 (localhost) — only connections from the same machine. Safe for development.
  • 0.0.0.0 — connections from anywhere that can reach the machine.

This causes a very common problem: your app works on your laptop, but deployed in a container or on a server, the platform can't reach it — 502 Bad Gateway or "connection refused." The app is listening on 127.0.0.1 inside the container, where nothing outside can see it. (HTTP Status Codes Explained.)

The fix is to listen on 0.0.0.0 in production, and use the port the platform gives you — usually in a PORT environment variable:

const port = process.env.PORT || 3000
app.listen(port, "0.0.0.0")

The reverse applies to databases: a database should not listen on a public address without a firewall. Plenty of data leaks come from databases exposed to the internet with weak or no passwords.

Firewalls and open ports

A firewall decides which ports accept connections from outside. On a public server, typically only 80, 443, and 22 (SSH, preferably restricted) should be open. Your database port should be reachable only from your app. Managed platforms configure this for you; on your own server, it's your job. (VPS vs PaaS.)

The summary

  • IP address = which computer. Port = which program on it.
  • localhost / 127.0.0.1 = this computer only.
  • 0.0.0.0 = listen on every interface — needed for apps in containers and on servers.
  • EADDRINUSE = something's already using that port.
  • Only expose the ports that need to be public.

EasySpawn routes your custom domain over HTTPS to the port your app listens on inside its workspace, and keeps databases private to your project — no firewall rules to write. See how it works or join the waitlist.

Related: What Is localhost? · What Is a Server? · Reverse Proxies Explained

Keep reading