Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 651
brucelin Avatar asked Sep 29 '18 15:09

brucelin


2 Answers

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)

like image 118
seyid yagmur Avatar answered Oct 21 '22 06:10

seyid yagmur


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

like image 30
Satish Patro Avatar answered Oct 21 '22 07:10

Satish Patro