DEV Community

Cover image for Why Does Vite Run on localhost:5173? It's Not Random!
Abhisek Roy
Abhisek Roy

Posted on AI-assisted

Why Does Vite Run on localhost:5173? It's Not Random!

React project run on localhost:3000.

Then you start a Vite project, and suddenly it's localhost:5173. πŸ€”

Why such a random number? I finally looked it up, and it's not random at all.

🏒 First, what is a port?

Think of your computer as an apartment building.

In real life On your computer
The building localhost (your own machine)
A flat number The port
The person living there Your running app

So localhost:5173 simply means:

"Go to my building and knock on flat 5173."

πŸ•΅οΈ The secret hidden in 5173

Squint a little and read it like this:

Number Letter Why
5 V Roman numeral for 5
1 I Looks like I
7 T Looks like T
3 E A flipped E

5173 = VITE ⚑

It's like a personalised number plate. At first you see digits, then you spot the name, and you can't unsee it.

πŸ”„ Vite used to live at 3000

Here's the part I didn't know: earlier versions of Vite used port 3000 too.

In Vite 3, the team changed the default to 5173 to move away from such a commonly used port.

Imagine flat 3000 is the most popular flat in the building. Many tools want to move in, but for a given address, only one can live there at a time. So Vite packed its bags and moved to a flat with its own name on it. πŸ“¦

A cartoon character jumping in excitement

Why was 3000 picked in the first place? I couldn't find a confirmed reason.

It's like a popular hangout spot. People keep going there because everyone already knows it.

😡 Why am I seeing 5174?

Sometimes your project opens on 5174 instead.

That means flat 5173 is already occupied, often by another Vite project you left running in a different terminal.

By default, Vite knocks on the next door:

5173 ❌ occupied
5174 βœ… free, moving in!
Enter fullscreen mode Exit fullscreen mode

If 5174 is busy too, it keeps looking.

πŸ› οΈ Want to choose the port yourself?

In vite.config.js:

import { defineConfig } from 'vite'

export default defineConfig({
  // keep your existing plugins here
  server: {
    port: 3000,
    strictPort: true,
  },
})
Enter fullscreen mode Exit fullscreen mode
  • port: the flat you want
  • strictPort: true: "This flat or nothing!" Vite stops with an error instead of trying the next one

Or do it just once from the terminal:

npm run dev -- --port 3000
Enter fullscreen mode Exit fullscreen mode

🎯 Quick recap

  • 🏒 A port is like a flat number
  • ⚑ 5173 can be read as VITE
  • πŸ“¦ Vite 3 moved the default from 3000 to 5173
  • πŸšͺ 5174 usually appears because 5173 is busy

Happy Coding :)

Like

Top comments (0)