title: How to track down error in node network code?
body: <p>I am trying to track down why my code is failing with this error:</p>
  
  <pre><code> { Error: connect ECONNREFUSED 127.0.0.1:443
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
     errno: 'ECONNREFUSED',
     code: 'ECONNREFUSED',
     syscall: 'connect',
     address: '127.0.0.1',
     port: 443 }
  </code></pre>
  
  <p>and the stack trace for that error looks like this:</p>
  
  <pre><code> Error: connect ECONNREFUSED 127.0.0.1:443
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
  </code></pre>
  
  <p>I am making a network connection, but I am not trying to connect to localhost.</p>
  
  <p>The network code I am using works just fine (and connects to the right host) in other contexts.</p>
  
  <p>I'm using node 11.6.0 as supplied by brew install, and it looks like the only occurrence of the string "net.js" in the brew "Cellar" directory structure is in the node binary itself. In other words, even after</p>
  
  <pre><code> brew install --build-from-source node
  </code></pre>
  
  <p>running</p>
  
  <pre><code> find /usr/local/Cellar/node/11.6.0 -type f | xargs fgrep -l net.js
  </code></pre>
  
  <p>only finds one file: /usr/local/Cellar/node/11.6.0/bin/node and there's no net.* files in that directory tree.</p>
  
  <p>If it matters, my code which seems to trigger this error looks like this:</p>
  
  <pre><code>  const get_json_with_auth= async (channel, url) =&gt; {
      const parsed_url= URL.parse(url);
     return new Promise((good, fail) =&gt; {
       let request= require('https').get({
         hostname: parsed_url.hostname,
         path: parsed_url.path,
         headers: {
           Authorization: get_auth('GET', channel, url)
         }
       });
       console.log('url', url);
       request.on('response', response=&gt; {
         const chunks= [];
         response.on('data', data=&gt; chunks.push(data));
         response.on('end', ()=&gt; good(JSON.parse(Buffer.concat(chunks).toString())));
       });
       request.on('error', err=&gt; fail(err));
     });
   };
  </code></pre>
  
  <p>(I'm on OSX high sierra here.)</p>
  
  <p>But, once again, the host name in the url I'm using does not resolve to localhost (and works just fine in other contexts).</p>
  
  <p>How do I isolate a problem like this?</p>