Dev server only works on localhost: expose Vite, Next.js, Angular
Make Vite, Next.js, Angular, Create React App and Django dev servers reachable from your phone or another computer with the host flag.
Most dev servers listen only on localhost, so a phone or another computer on the same Wi-Fi cannot open them. Tell the server to listen on all addresses, then open your computer's IP address with the port.
What to do, step by step
- Find your computer's local IP address, such as 192.168.1.25.
- Start the dev server with the host option for your tool (see the table below).
- On your phone, connected to the same Wi-Fi, open http://192.168.1.25:PORT with your own address and the port.
- If it still does not open, allow the port in your firewall for private networks.
- Turn the option off again when you are not testing, so your server is not open to the network.
Commands you can copy
npm run dev -- --hostnpx next dev -H 0.0.0.0python manage.py runserver 0.0.0.0:8000Option for each tool
- Vite
npm run dev -- --hostor setserver.host: truein vite.config.js.- Next.js
next dev -H 0.0.0.0- Angular
ng serve --host 0.0.0.0- Create React App
- Set the variable first:
HOST=0.0.0.0 npm start(on Windows useset HOST=0.0.0.0). - Django
python manage.py runserver 0.0.0.0:8000, and add your IP to ALLOWED_HOSTS.- Flask
flask run --host=0.0.0.0- Phone still cannot connect
- Check both devices use the same Wi-Fi, a VPN is off, and the router does not use client isolation (a guest network setting).
Questions about Dev server not reachable from network
- Is it safe to listen on 0.0.0.0?
- On your home network it is fine for testing. On public Wi-Fi anyone nearby could open your dev server, so switch it off there.
- What is my computer's IP address?
- Run ipconfig on Windows or ifconfig / ip a on macOS and Linux and look for an address like 192.168.x.x. The open-from-phone page on this site shows how.
- Why does it say "Network: use --host to expose"?
- That is Vite telling you the server is localhost only. Add --host to share it on your network.
Free tools that help
- Subnet calculatorEnter an IPv4 address with a prefix or netmask to get the network, broadcast, host range, wildcard mask and usable hosts. Split into subnets.
- Common ports listSearch a list of common TCP and UDP port numbers: SSH 22, HTTP 80, HTTPS 443, MySQL 3306, PostgreSQL 5432 and more, with dev server ports.