How to run my Angular site on mobile device that is running localhost on my windows desktop

H. Pauwelyn picture H. Pauwelyn · Mar 28, 2017 · Viewed 50.4k times · Source

I know from this question and answer on Super User Site running on localhost on desktop is unreachable on android device (PS: this question continues on the question in the link) that the command ng serve opens a bad configured webserver.

The question is how could I run my site on an Android device without deploying my site. I'll try to run the site on this url http://192.168.0.168:4200 using Angular-CLI.

Answer

Ahmed Musallam picture Ahmed Musallam · Mar 28, 2017

try ng serve --host option as explained in this issue: https://github.com/angular/angular-cli/issues/1793 comment by intellix.

  1. ng serve --host 0.0.0.0
  2. Find your local IP address by following this
  3. Navigate to <local IP adress>:4200 from any device on the same network.

NOTE: If you get CONNECTION_REFUSED just disable your firewall and you should be good to go.

otherwise, try https://ngrok.com/ to open a tunnel from your local network to your computer's localhost. Basically your computer forwards the 4200 port to an external IP and port that any device on the network can access.