'Access to localhost from other machine - Angular

Background

Most developers often use two or more desktops and laptops when they're working on a project. Same for me, and now I'm working on an Angular project.

GOAL

I want to access localhost:4200 from another device, so I can check the UI updates without switching windows on a device.

I took some research and tried the below angular-CLI command.

ng serve --host=MyLocalIP
ng serve --host 0.0.0.0

But no luck until yet. Is there a better way to achieve this?



Solution 1:[1]

Using ng serve --host 0.0.0.0 command has solved my problem. Type 192.168.x.x:4200 to get access to the app from another machine.

Also, check for firewall rules on client and server (disable firewall temporally or create a rule to allow traffic)

Solution 2:[2]

Two options are there

ng serve --host 0.0.0.0

To check, if this is not working, 1st try to hit from the same computer where you run ng serve, to get to know if you can access through the firewall

ng serve --host 192.168.X.X

192.168.X.X is the IP address of my pc(you can use ipconfig(windows), ifconfig(Linux) to see your IP) After that, you can access 192.1668.X.X:4200 instead of localhost:4200

Nothing related:- Even if you change some code and server refresh to show updated code, it will refresh in other machines too

If you can not able to access 192.168.X.X:4200. You may be in a network where firewall protection is blocking. SO, connect to your personal network and check

Solution 3:[3]

ng serve --host 192.168.X.X --port 9000

Solution 4:[4]

Using ng serve --host 0.0.0.0 will allow you to connect to the ng serve using your ip instead of localhost.

NOTE

In newer versions of the cli, you have to provide your local ip address instead

NOTE

In newer versions of the cli you can use 0.0.0.0 as the ip again to host it for anyone on your network to talk to.

As a side note Make sure your connection is set to Public in your OS settings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brijesh Kalkani
Solution 2
Solution 3 harsh gupta
Solution 4