rvaliev
rvaliev

Reputation: 1091

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

Upvotes: 15

Views: 9506

Answers (3)

nemanjabu
nemanjabu

Reputation: 80

Vagrant (VM) doesn't trigger file change events. This bug is reported to VirtualBox community and is set to won't fix. For now it's not possible to work with Angular 2 via Vagrant. See this issue on GitHub for relevant discussion on this.

Upvotes: 3

michelepatrassi
michelepatrassi

Reputation: 2086

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:

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

Upvotes: 38

Denis Prša
Denis Prša

Reputation: 71

You have to add some config to Vagrantfile.

To access site add these lines (it helped me):

config.vm.network "private_network", ip: "192.168.100.100"
config.vm.network "forwarded_port", guest: 4200, host: 4200
config.vm.network "forwarded_port", guest: 49152, host: 49152

You can access site on: http://192.168.100.100:4200/

Upvotes: 7

Related Questions