Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default port 5000 in svelte?

I am not getting how to change the default 5000 port in Svelte to some other port if we install the sample template through degit.

like image 615
Hypermystic Avatar asked Aug 20 '19 17:08

Hypermystic


People also ask

How do I change the default port for svelte?

It uses the npm run dev command to start sveltekit applications and the default port listens at 3000. You can add --port or -p option to use new port number.

What port does svelte use?

📚 SvelteKit Port By default SvelteKit will run on port 5173 . If you already have another tool running on that port, the command will automatically find another, free port.


3 Answers

The sveltejs/template uses sirv-cli.
You can add --port or -p in your start:dev script in package.json.

Instead of:

"start:dev": "sirv public --single --dev"

Use:

"start:dev": "sirv public --single --dev --port 5555"

You can see more of sirv-cli options:

https://github.com/lukeed/sirv/tree/master/packages/sirv-cli

like image 170
CD.. Avatar answered Oct 18 '22 05:10

CD..


You can use env vars HOST and PORT.

From https://www.npmjs.com/package/sirv-cli:

Note: The HOST and PORT environment variables will override flag values.

Like this:

HOST=0.0.0.0 PORT=6000 npm run dev
like image 20
Francky Avatar answered Oct 18 '22 03:10

Francky


Go to package.json, you will find this line:

"start": "sirv public --no-clear"

Change it to this, or to any other port that you want:

"start": "sirv public --no-clear  --port 8089"
like image 2
Ronivon de Matos Avatar answered Oct 18 '22 04:10

Ronivon de Matos