Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

Port 4321 Is in Use: Why Is My Astro Site on Port 4322?

Astro says Port 4321 is in use, trying another one, and opens on 4322. Something else is using the port. Here's what that means and how to get 4321 back.

Tested on Astro 7.4

Cover image for Port 4321 Is in Use: Why Is My Astro Site on Port 4322?
In this guide
  1. Why it happens
  2. How to fix it
  3. Still stuck?
  4. Where to go next
  5. Frequently asked questions

Your site is on port 4322 because something else is already using port 4321. Often, it’s another Astro dev server you forgot to stop. Astro doesn’t crash. It says Port 4321 is in use, trying another one... and picks the next free number. Open the new address, or stop the old server to get 4321 back.

Why it happens

A port is like a door number on your computer. Astro uses door 4321 by default. Only one program can use a door at a time.

If 4321 is taken, Astro tries 4322, then 4323, and so on. It uses the first free one.

We tested this on Astro 7.4. Our computer already had dev servers open on 4321 to 4324. Then we started a fresh project:

Terminal
$ npm run dev
[vite] Port 4321 is in use, trying another one...
[vite] Port 4322 is in use, trying another one...
[vite] Port 4323 is in use, trying another one...
[vite] Port 4324 is in use, trying another one...
astro  v7.4.7 ready in 146 ms
┃ Local    http://localhost:4325/
┃ Network  use --host to expose

We cut out the times and a few extra lines. So the site opened at localhost:4325. Look at the line that says Local. That’s always the right address.

Terminal
$ npm run dev
Another astro dev server is already running.
URL:  http://localhost:4325
PID:  2664
Run `astro dev stop` to stop it, or use `astro dev --force` to replace it.

How to fix it

You don’t have to fix anything. Your site works fine on 4322. But if you want 4321 back, here’s how.

  1. Find the old terminal window. Look for another terminal tab that’s still running npm run dev. Click in it and press Ctrl and C to stop it.
  2. Stop it from the project folder. If you can’t find the window, go to that project in a terminal and run npx astro dev stop. We ran it, and it said Stopped dev server (pid 1719).
  3. Start again. Run npm run dev. Astro should now say localhost:4321.

Want to pick your own port instead? Add --port and a number:

Terminal
$ npx astro dev --port 4500
 astro  v7.4.7 ready in 164 ms
┃ Local    http://localhost:4500/

Still stuck?

  • If the page at the new address is blank or broken, the port isn’t the problem. Read the error in your terminal.
  • Paste the full terminal output into an AI. Our guide on fixing Astro errors with AI shows what to say.
  • Ask in our community.

Where to go next

Frequently asked questions

Is it bad if my site runs on port 4322?

No. Your site works the same on any port. Just open the address Astro shows you. The only problem is an old server still running somewhere.

What does Another astro dev server is already running mean?

You started the dev server twice in the same project. Astro won't start a second one. Run npx astro dev stop to stop the old one, then start again.

How do I pick my own port?

Add --port and a number. For example, npx astro dev --port 4500 opens your site at localhost:4500.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".