Node JS: Automatic selection of `http.get` vs `https.get`

I had a similar need, but didn’t need the full blown request or needle libraries, I have the following code (which is slightly different)

var adapterFor = (function() {
  var url = require('url'),
    adapters = {
      'http:': require('http'),
      'https:': require('https'),
    };

  return function(inputUrl) {
    return adapters[url.parse(inputUrl).protocol]
  }
}());
//.. and when I need it
adapterFor(url).get(url, ...)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)