I want to change host name for testing purpose. I have tried ng serve --host 0.0.0.0 but app again runs on localhost:4200. Is there a way that app runs on different host name (word) in browser?
I want to change host name for testing purpose. I have tried ng serve --host 0.0.0.0 but app again runs on localhost:4200. Is there a way that app runs on different host name (word) in browser?
Share Improve this question asked Feb 19, 2018 at 18:27 Umair JameelUmair Jameel 1,6733 gold badges31 silver badges58 bronze badges 3- I mean, wrote something else here, I wrote the actual port actual port. But I want to word to be shown. – Umair Jameel Commented Feb 19, 2018 at 18:31
-
It has to be
localhost
though as the launch point, it is running on your PC and that address will always point back to your PC. That is not configurable, only the port number is. – Igor Commented Feb 19, 2018 at 18:33 -
1
@lgor -
0.0.0.0
is legal for the--host
parameter forng serve
. It's simply tellingng
how to bind. Using0.0.0.0
is basically tellingng
that it can accept requests from any IP address. The default binding is127.0.0.1
and thus only requests from the local machine will work - but it actually doesn't matter the hostname (localhost
or a custom one). – Randy Commented Feb 19, 2018 at 18:41
2 Answers
Reset to default 7If you're on Mac or Linux and just for local testing, you can edit /etc/hosts
and add your own dns mapping. I'm sure you can do something similar on Windows.
For example you can add adding mysite
to your hosts file:
127.0.0.1 mysite
Then you can access your app by going to http://mysite:4200
.
Note that if making changes to your hosts file don't appear to work you may need to either reboot or make your OS reload your hosts file. See the bottom of this page for more information: https://www.imore./how-edit-your-macs-hosts-file-and-why-you-would-want
- Add the next row to the end of your hosts file: 127.0.0.1 my.local.host
- Start app: ng serve --host "my.local.host"