Access Angular app outside of localhost

Angular local host network

When you run npm start or ng serve on an Angular app, you can access your Angular app on localhost

But what if you want to access the server from outside the machine you are working on. For example you want to test your app on a mobile device.

You can’t perform anng serve on your phone and run the code locally on your phone.

So instead you can run ng serve --host 0.0.0.0

This will expose your app on your local network.

Then to access the Angular on another device, find out the IP address of the computer that is acting as the server (where your code is running) and then enter that IP address on another device.

To find out the IP address of your Mac, type ifconfig into a terminal and it will reveal your Macs local network IP address.

E.g if the IP address of the server is 192.168.1.101, then you can go to 192.168.1.101:4200 on your phone and your Angular app will load!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.