title: Node JS: Automatic selection of `http.get` vs `https.get`
body: <p>I have a Node JS app that needs to download a file, given a URL at run-time.</p>
  
  <p>The URL may be either <code>http://</code> or <code>https://</code>.</p>
  
  <p>How do I best cater for the different protocols?</p>
  
  <p>At the moment I have:</p>
  
  <pre><code>var http = require('http');
  var https = require('https');
  
  var protocol = (parsedUrl.protocol == 'https:' ? https : http);
  protocol.get(parsedUrl, function(res) {
    ...
  });
  </code></pre>
  
  <p>... but it feels clunky.</p>
  
  <p>Thanks!</p>