Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

http://localhost:4200 from windows is working with ng serve from WSL2, how come?

When I run "ng serve" from WSL2 (Ubuntu 20.04), I am able to access the angular application from Windows 10 Host by browsing to http://localhost:4200.

Can someone explain how this is possible? I understand that WSL2 is working as a virtual machine with its own ip address. How can Windows 10 host access the angular app on WSL2 using "http://localhost:4200" ?

On a different note, when I run tomcat from WSL2, I am NOT able to access the tomcat application from Windows using "http://localhost:8080".

Thanks in advance Paul

like image 240
paulk93 Avatar asked Oct 25 '25 05:10

paulk93


1 Answers

The assumption that WSL2 is working as a virtual machine with its own ip address depends on the Windows 10 version.

Also read this article. It explains why and how.

Accessing Linux networking apps from Windows (localhost)

If you are building a networking app (for example an app running on a NodeJS or SQL server) in your Linux distribution, you can access it from a Windows app (like your Edge or Chrome internet browser) using localhost (just like you normally would).

However, if you are running an older version of Windows (Build 18945 or less), you will need to get the IP address of the Linux host VM (or update to the latest Windows version).

like image 150
Dudi Boy Avatar answered Oct 26 '25 20:10

Dudi Boy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!