"Address not available" error at ng serve with Angular

Viewed 3270

I'm trying to compile a simple (first) Angular project on Visual Studio. I'm connected to a Hotspot. When I run ng serve I get the following error:

An unhandled exception occurred: listen EADDRNOTAVAIL: address not available 40.68.249.35:4200 See "/private/var/folders/jc/mgkz9l6x7h52sz7dcp8mrr_m0000gn/T/ng-3legRp/angular-errors.log" for further details.

[error] Error: listen EADDRNOTAVAIL: address not available 40.68.249.35:4200
at Server.setupListenHandle [as _listen2] (net.js:1296:21)
at listenInCluster (net.js:1361:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)

How can I solve this error? Currently I always use the command ng serve --host 0.0.0.0 which works...

3 Answers

Try this ng serve --port=7845

You can use any other port also.

Go to your angular.json, Have you specified a host?

"serve": {
      ...
        "development": {
          ...
          "host": "example.com",
        },

Make sure example.com is included in your /etc/hosts file.

$ vi /etc/hosts
127.0.0.1   localhost   example.com

I was having the same error when trying to use my external IP. When I tried ng serve --host 0.0.0.0 it worked fine but I was only able to connect with my LAN IP4 address (192.168.1.110) but I was not able to access the application with the external IP.

I fix this by doing Port Forwarding on my router on port 4200 so that it redirects from the external IP to the local IP, after that, I run ng serve --host 0.0.0.0, and I was able to access the application with the external IP.

Related