ng serve method ip not open in another machines
OS?
Windows 8
Versions.
Could not start watchman; falling back to NodeWatcher for file system events. Visit http://ember-cli.com/user-guide/#watchman for more info. angular-cli: 1.0.0-beta.16 node: 6.6.0 os: linux ia32
After instal angular-cli for below step
npm install -g angular-cli
ng new PROJECT_NAME
cd PROJECT_NAME
After given below command
ng serve
http://localhost:4200 and http://127.0.0.1:4200 is working on same machine only if i open that machine ip with other machine means not opening. How to open the webpage in another machines, like that machine ip is 10.88.186.126 means how to open this url http://10.88.186.126:4200 in other machines browsers in the N/W.
The solution is simple. Just bind to the correct interface address via ng serve --host=0.0.0.0
@Coksnuss ,
Hi thanks for your reply any possible way to set in file for default ip for run time
@Coksnuss ,
Is building this method but not running in browser
ng serve --host 10.0.136.126
Not sure about the run-time setting. Regarding the binding: Bind to 0.0.0.0 (literally).
Looks like the default host address cannot be set in any other way.
The default setting (localhost) is hardcoded (https://github.com/angular/angular-cli/blob/master/packages/angular-cli/commands/serve.ts#L41) and ember CLI seems not to provide an alternative way to specify arguments (other than by passing it as argument switch) (https://ember-cli.com/api/files/lib_models_command.js.html)
However, you may set the PORT environment variable to override the default port 4200
Oh ok we can given manual at build time only correct.
10.0.136.126 is private ip, use the public ip ;)
@fedecordova private that one is ok how can i access in other machines that is a issue :+1:
use a digitalocean droplet, like ubuntu
using following in the package.json makes it accessible to the host machine ng serve --host 0.0.0.0
In case you get Invalid Host header, use ng serve --host=0.0.0.0 --disable-host-check
The option '--disable-host-check' is not registered with the serve command. Run ng serve --help for a list of supported options.
I got it working by actually putting my local ip in the host.
ng serve --host=yourLocalIPHere
Hope this helps. :)
@Coksnuss thank you, I write these lines in the .angular-cli.json file
"defaults": {
"serve": {
"host": "0.0.0.0",
"port": 4201
},


All fine now XD
@LordAlastair Thanks for pointing that out! Very helpful
@abhishekdgeek thank you, this problem drove me crazy I put my local ip and it finally worked
If you want to save the effort of adding the --host flag everytime you run your app just add an entry to the 'defaults' prop in the angular-cli.json file like shown below:
angular-cli.json
{
// .....
"defaults": {
"styleExt": "css",
"component": {},
"serve": {
"host": "0.0.0.0",
"port": 9876
}
}
@LordAlastair @gsivaprabu @Coksnuss thank you, very helpful !!!
In Dockerfile:
CMD ["ng", "serve", " --host 0.0.0.0", "--port 4201"]
frontend_1 | The option '--port 4201' is not registered with the serve command. Run `ng serve --help` for a list of supported options.
frontend_1 | ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Same goes for host is port parameter is not used.
CMD ["ng", "serve", " --host 0.0.0.0", "--port 4201"]
Should be CMD ["ng", "serve", " --host", "0.0.0.0", "--port", "4201"]
Or even better ENTRYPOINT ["ng", "serve"] CMD [" --host", "0.0.0.0", "--port", "4201"]
run angular with command - ng serve --host=0.0.0.0 --disable-host-check this will disable host check and allow to access with IPAddress