What is localhost:3000?
// the internet's most-visited address that nobody else can visit
~/my-cool-site $ npm run build && npx serve
compiling static site ████████████ 100%
✓ built ./dist in 1.2s
- serving on http://localhost:3000
opening http://localhost:3000 ...
1 localhost is your computer.
Visit it, and your machine just talks to itself.
- It's the loopback address
127.0.0.1. - Nothing leaves your computer. No internet involved.
- So only you can open it. No one else.
your browser
your computer
localhost = 127.0.0.1
2 :3000 is a door.
A port is just a door on one building: your computer.
- Your computer has 65,535 doors, so apps never collide.
- Dev tools knock on door
:3000: Next.js, CRA, Express, Rails. localhost:3000= your computer, door #3000
your computer
one building · many doors
3 localhost ≠ internet
Open localhost and the request loops inside your own machine.
- Your browser asks your laptop.
- Your laptop answers itself.
- The internet stays out of it.
loops back home, never out