Node.js EADDRNOTAVAIL wrong IP address -SOLVED

nodejs

#1

According to docs

Cloud9 hosted workspaces now allow workspaces to listen on multiple ports. The following ports are supported (along with the urls they can be accessed from):

8080 -> https://-.c9users.io
8081 -> http://-.c9users.io:8081
8082 -> http://-.c9users.io:8082

My app is configured to use port 8081

When I run the app, error shows a wrongly assigned IP address (different each time) instead of 0.0.0.

Watching for changes
ready to watch file changes
Starting Server
webserver available at http://xxxx-xxxxxx.c9users.io:8081


Ready
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL **104.154.99.93**:8081
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at Server._listen2 (net.js:1246:19)
    at listen (net.js:1295:10)
    at net.js:1405:9
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)

How do I configure port 8081 to resolve to 0.0.0.0.?


#2

Which host you use use for creating the server? From the output it seems to be xxxx-xxxxxx.c9users.io. You need to use 0.0.0.0 instead since c9user.io is the public address of the proxy. Or modify your /etc/hosts file echo "0.0.0.0 $C9_HOSTNAME" | sudo tee -a /etc/hosts


#3

When I open /etc/hosts

127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Bear with me, as I don’t understand your answer 100%. I’m trying to understand why I get the error. Note the dynamic IP address in the output: 104.154.99.93 or should the IP address be 0.0.0.0 with xxxx-xxxxxx.c9users.io:808x as my public address?

My app framework webserver json was:

          "enabled": true,
          "host": "localhost",
          "port": 8081
        }

I changed it to

          "enabled": true,
          "host": "xxxx-xxxxxx.c9users.io",
          "port": 8081
        }

Which resulted in the error and output in my post. What should localhost be ?


#4

host should be changed to 0.0.0.0, xxxx-xxxxxx.c9users.io is the public address of the proxy, 8081 is not a part of the host


#5

Ok thanks, that worked for me

      "host": "0.0.0.0",
      "port": 8081

http://xxxx-xxxxxx.c9users.io:8081


#6

However I have a similar problem in next steps:
to resolve “localhost” in framework json …If you could tell me what these are doing