Port 4321

What’s running on port 4321 on my Mac?

4321 is Astro’s countdown of a port, used by both astro dev and astro preview. If you run Starlight docs next to your main site, you’ll meet it twice.

Commonly used by

  • Astro dev serverastro dev (npm run dev) serves on localhost:4321 and moves up if it’s busy.
  • Astro previewastro preview serves the built site on the same default port.
  • StarlightDocs built on Astro inherit the 4321 default.

Check what’s on port 4321

lsof -nP -iTCP:4321 -sTCP:LISTEN

It’s a node process. Two Astro projects look identical in that list, so check the working folder and whether it’s dev or preview:

ps -o pid,etime,command -p <PID>
lsof -a -p <PID> -d cwd -Fn | tail -1

With Stat Space: statspace port 4321.

Free it

Stop it with kill <PID>. Astro doesn’t fail when 4321 is taken: it moves to 4322, 4323 and so on. That keeps your new server running but can leave an old one behind for days. To check the whole range at once:

lsof -nP -iTCP:4321-4330 -sTCP:LISTEN

Change the port

From the command line:

astro dev --port 4400
astro preview --port 4400

Or once, in astro.config.mjs:

export default defineConfig({
  server: { port: 4400 },
});

server can also be a function that receives { command }, which lets you give dev and preview different ports so they never collide.

Who can reach it

By default Astro binds to localhost, so only your Mac can connect. --host or server: { host: true } listens on all addresses, and Astro prints a Network URL. That’s handy for testing on a phone, but it also serves your drafts, unpublished pages and any server endpoints to everyone on the network. See dev server exposed to the network.

Seeing it live

Stat Space shows 4321 as an Astro server with its project folder, the launcher that started it and its uptime. With several Astro sites running, each row names its own folder, and --host sessions get flagged.

Questions

Why is my Astro site on 4322?

Something already held 4321, usually another Astro project or a preview you forgot. Astro picks the next free port and prints it. Run lsof -nP -iTCP:4321 -sTCP:LISTEN to find the first one.

How do I open the Astro dev server on my phone?

Run astro dev --host (or set server: { host: true }), then open the Network URL it prints. Turn it off afterwards on shared networks.

Does Astro use Vite's port 5173?

No. Astro runs Vite under the hood but sets its own default of 4321, so Astro and a plain Vite app can run side by side.

Get started

Know what your Mac is doing, without adding to it.

Free, no account. Pro is $9.99 once for the first 100 buyers.