To open a Vite development app from another device on your network, run this from the directory containing package.json:

npm run dev -- --host 0.0.0.0

Keep the terminal running and open the Network URL Vite prints on the second device. Both devices need a network connection that permits them to reach each other. On your phone, localhost refers to the phone itself, not your development computer.

Check that your dev script runs Vite

The command assumes your project has a script such as:

{
  "scripts": {
    "dev": "vite"
  }
}

This is an excerpt, not a replacement for your entire package.json. Run npm run to list the scripts in your project. If dev starts another framework, check that framework's options: --host is not a universal setting for every Node server.

Why there are two sets of dashes

In npm run dev -- --host, the standalone -- tells npm to forward the following arguments to the script. --host is then received by Vite. The npm run documentation describes argument forwarding.

Command Meaning in a project whose dev script is vite
npm run dev Start the development server using its configured defaults.
npm run dev -- --host Forward the host flag to Vite.
npm run dev -- --host 0.0.0.0 Explicitly bind the server to all IPv4 interfaces.
npm run dev -- --host 0.0.0.0 --port 5174 --strictPort Use port 5174 and fail if it is unavailable.

Use the explicit argument separator rather than relying on npm run dev --host. Also, npm run host only works if your project defines a script named host.

Open the right address

For example, if the terminal reports a network address of http://192.168.1.42:5173/, enter that full address on the other device. Use your computer's actual address and the port printed in your terminal.

0.0.0.0 describes where the server listens. It is not the address to send to another person. Vite's server options explain host binding and the default localhost behavior.

A development server should be reachable only by people you intend to share the project with. Use a trusted network, keep the firewall enabled, and stop the process with Ctrl+C when the session is finished.

Fix common connection problems

Symptom What to check next
It works on the laptop but not the phone Use the laptop's network address. Check that the phone is on Wi-Fi rather than mobile data.
The connection times out Check the firewall's rule for the development server, VPN routing and guest Wi-Fi device isolation.
The terminal says the port is occupied Stop the specific conflicting server or choose another port. Follow the address already in use guide.
The page loads but API requests fail Inspect the API URL in the browser's network panel. A hard-coded localhost API address points to the device opening the page.
Vite rejects a custom hostname Add only a hostname you control to server.allowedHosts; do not set it to true to bypass the check.
The server runs in Docker or WSL Check the container's published port or WSL network configuration as well as Vite's host setting.

Changing the host setting cannot fix a backend URL, a blocked network route or an application error. Work through the failing connection rather than repeatedly restarting the frontend.

Save the setting for repeated local testing

Merge this into your existing vite.config.js, retaining your plugins and other settings:

import { defineConfig } from 'vite';

export default defineConfig({
  server: {
    host: '0.0.0.0',
    port: 5173,
    strictPort: true,
  },
});

The Vite CLI reference documents the equivalent command-line flags. A separate LAN-testing script is another option if you want ordinary development to keep its localhost default.

Share a deployed app with customers

For ongoing public access, deploy the app. A local development server depends on your computer, terminal session and network. Vite's deployment guide explains production builds and notes that vite preview is also a local preview tool.

AppJet can build and deploy full-stack applications to a public URL. Free includes hosting for regular live applications within its published resources. Your AI coding allowance and your deployed app's traffic are separate. For a conventional Node deployment, continue with the Node.js hosting guide.