Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve method ip not open in another machines #2542

Closed
sivaprabug opened this issue Oct 6, 2016 · 26 comments
Closed

ng serve method ip not open in another machines #2542

sivaprabug opened this issue Oct 6, 2016 · 26 comments

Comments

@sivaprabug
Copy link

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.

@schnz
Copy link

schnz commented Oct 6, 2016

The solution is simple. Just bind to the correct interface address via ng serve --host=0.0.0.0

@sivaprabug
Copy link
Author

@Coksnuss ,

Hi thanks for your reply any possible way to set in file for default ip for run time

@sivaprabug
Copy link
Author

@Coksnuss ,

Is building this method but not running in browser

ng serve --host 10.0.136.126

@schnz
Copy link

schnz commented Oct 6, 2016

Not sure about the run-time setting. Regarding the binding: Bind to 0.0.0.0 (literally).

@schnz
Copy link

schnz commented Oct 6, 2016

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

@sivaprabug
Copy link
Author

Oh ok we can given manual at build time only correct.

@fedemzcor
Copy link

10.0.136.126 is private ip, use the public ip ;)

@sivaprabug
Copy link
Author

@fedecordova private that one is ok how can i access in other machines that is a issue 👍

@fedemzcor
Copy link

use a digitalocean droplet, like ubuntu

@pradhyu
Copy link

pradhyu commented Mar 23, 2017

using following in the package.json makes it accessible to the host machine
ng serve --host 0.0.0.0

@Tobiaqs
Copy link

Tobiaqs commented Jul 19, 2017

In case you get Invalid Host header, use ng serve --host=0.0.0.0 --disable-host-check

@abhishekdgeek
Copy link

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. :)

@LordAlastair
Copy link

LordAlastair commented Nov 7, 2017

@Coksnuss thank you, I write these lines in the .angular-cli.json file
"defaults": { "serve": { "host": "0.0.0.0", "port": 4201 },
image

image

All fine now XD

@schnz
Copy link

schnz commented Nov 7, 2017

@LordAlastair Thanks for pointing that out! Very helpful

@ammaralsayed
Copy link

@abhishekdgeek thank you, this problem drove me crazy
I put my local ip and it finally worked

@jqp5000
Copy link

jqp5000 commented Mar 24, 2018

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
    }
}

@aswinkumarrhex
Copy link

aswinkumarrhex commented Apr 11, 2018

@LordAlastair @gsivaprabu @Coksnuss thank you, very helpful !!!

@holms
Copy link

holms commented Apr 23, 2018

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.

@schnz
Copy link

schnz commented Apr 23, 2018

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"]

@pallapraveen
Copy link

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

@Balajishivankar
Copy link

Run angular 4 project with this cmd
ng serve --host yourIPaddress
i.e. ng serve --host 192.168.33.178

@vnextcoder
Copy link

vnextcoder commented Jun 26, 2018

I get the option '--disable-host-check' is not registered with the serve command. Run `ng serve --help` for a list of supported options.

@rizz5091660
Copy link

You guys are superb, i am noob in angular, been looking this answer for few days. Thanks a lot :)

@debugly
Copy link

debugly commented Oct 17, 2018

"serve": { "host": "0.0.0.0", "port": 4201 }

I want to know Angular CLI: 6.2.1 how to config the angular.json ?

@wdavilaneto
Copy link

on "serve" put somthing like
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"host": "0.0.0.0",
"browserTarget": "m3front:build",
"proxyConfig": "proxy.conf.json"
},
"configurations": {
"production": {
"browserTarget": "m3front:build:production"
}
}
}
.....

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests