title: Inexplicable node.js http throwing connect ECONNREFUSED (IPv6?)
body: <p>I am running node.js as follows:</p>
  
  <pre><code>&gt; http = require('http')
  &gt; http.get('http://myhost.local:8080',
      function (res) { console.log("RES" + res) }
    ).on('error', function (e) { console.log("Error:", e) })
  
  &gt; uri = require('url').parse("http://myhost.local:8080")
  { protocol: 'http:',
    slashes: true,
    auth: null,
    host: 'myhost.local:8080',
    port: '8080',
    hostname: 'myhost.local',
    hash: null,
    search: null,
    query: null,
    pathname: '/',
    path: '/',
    href: 'http://myhost.local:8080/' }
  &gt; http.get(uri,
      function (res) { console.log("RES" + res) }
    ).on('error', function (e) { console.log("Error:", e) })
  </code></pre>
  
  <p>An error is thrown for both the implicit and explicitly parsed URI and I get the following output for both:</p>
  
  <blockquote>
    <p>Error: { [Error: connect ECONNREFUSED]
      code: 'ECONNREFUSED',
      errno: 'ECONNREFUSED',
      syscall: 'connect' }</p>
  </blockquote>
  
  <p>The host <code>myhost.local</code> is an alias for <code>localhost</code> in <code>/etc/hosts</code>, being:</p>
  
  <pre><code>127.0.0.1   localhost myhost.local myhost
  255.255.255.255 broadcasthost
  ::1             localhost myhost.local myhost
  fe80::1%lo0 localhost myhost.local myhost
  </code></pre>
  
  <p><em>EDIT</em>: I tried virtually every permutation for the hosts file, including the most obvious:</p>
  
  <pre><code>127.0.0.1   localhost 
  255.255.255.255 broadcasthost
  ::1             localhost myhost.local myhost
  fe80::1%lo0 localhost
  </code></pre>
  
  <p><em>EDIT</em> I should also mention that I have tried this on more than one Mac now.</p>
  
  <p>Although it seems this is a rather common error, I have seen no useful explanations or workarounds. Here are some notable related facts:</p>
  
  <ol>
  <li>Running <code>$ wget http://myhost.local:8080</code> works as expected, so it isn't a firewall problem.</li>
  <li>Running <code>$ telnet myhost.local 8080</code> and then manually GET'ing the url works fine, so it's not a weird HTTP problem.</li>
  <li>I have no trouble using node.js to connect to other hosts e.g. <a href="http://www.google.com" rel="noreferrer">http://www.google.com</a></li>
  </ol>
  
  <p>I expect the useful system information would include: </p>
  
  <pre><code>$ node -v
  v0.9.11
  
  $ uname -a
  Darwin myhost.local 12.2.1 Darwin Kernel Version 12.2.1:
  Thu Oct 18 12:13:47 PDT 2012; root:xnu-2050.20.9~1/RELEASE_X86_64 x86_64
  
  $ sw_vers
  ProductName:    Mac OS X
  ProductVersion: 10.8.2
  BuildVersion:   12C3104
  
  $ sudo  netstat -nalt | grep LISTEN | grep 8080
  tcp6       0      0  ::1.8080  *.*    LISTEN
  </code></pre>
  
  <p>Does anyone have any idea what is going on here, and what a fix might be?</p>