Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run angular-cli from Vagrant box?

I've installed angular-cli with node v6.5.0 and npm v3.10.3 to my vagrant (Scotch) box. After running 'ng serve --port 4201' I can see that the build was successful and that the app is now serving on http://localhost:4201/

However I can't just use above address because I'm running on VM. I've tried to add '127.0.0.1:4201' to hosts file on host machine, but can't get anything working.

Thx

like image 520
rvaliev Avatar asked Sep 08 '16 21:09

rvaliev


1 Answers

Run ng serve like this:

ng serve --host 0.0.0.0

This will make the server in your vagrant machine accessible from outside using its ip (mine is 192.168.10.10 using homestead) and the default 4200 port for angular serve (http://192.168.10.10:4200).

Some more info:

  • StackOverflow answer:

127.0.0.1 is a loopback address so if you assign this IP (or localhost) to the config of your server, its not accessible from other network interfaces, so you cannot access it from outside of the VM. If you bind your server to 0.0.0.0 its available to all interfaces

  • Angular CLI
like image 197
michelepatrassi Avatar answered Sep 19 '22 13:09

michelepatrassi