Scott Whittaker

Frontend Developer

Day job React | side projects Svelte

Expose Sveltekit build to your network

When running a Sveltekit application locally it is not exposed to your network by default. If you want to test your application on other devices on your network then you need to tell Sveltekit to expose the application with the --host flag.

With npm run dev the CLI output tells you the application is available on localhost e.g. http://127.0.0.1:5173/ and also shows a message Network: use --host to expose. Note that at the time of writing this relates to @sveltejs/[email protected].

$ npm run dev 

    VITE v4.0.1  ready in 827 ms
    
  Local:   http://127.0.0.1:5173/
  Network: use --host to expose
  press h to show help

Use the flag to expose the network as follows and the console shows you the network addresses that your application is available at. You can now test your application on other devices on your network such as a tablet, phone or TV.

$ npm run dev -- --host

  VITE v4.0.1  ready in 944 ms

  Local:   http://localhost:5173/
  Network: http://192.168.0.xxx:5173/
  Network: http://192.168.0.xxx:5173/

You can also specify a port number if desired.

$ npm run dev -- --host --port 3333