title: Imgur API call: 443 ENOTFOUND error troubleshooting
body: <p>I'm receiving the same error every time I call the following node.js code. I haven't used Authorization Headers before in node.js, so I must be doing something wrong. Help or point me towards good documentation? The code is trying to retrieve as search for 'yellow' in imgur's library. My console always prints the same ENOTFOUND error each time I try to run it.</p>
  
  <pre><code>var express = require("express");
  var moment = require("moment");
  var http = require("http");
  var express = require("express");
  var moment = require("moment");
  var https = require("https");
  var mongo = require('mongodb').MongoClient;
  
  var mystatus="";
  var app=express();
  
  var imgurClientID = "&lt;my id&gt;";
  var imgurClientSecret = "&lt;my client secret&gt;";
  
  var options = {
      hostname: 'https://api.imgur.com/3/gallery/search?q=yellow',
      method: "POST",
      headers:{
         Authorization: imgurClientID, 
      }
  }
  
  app.get('/home', function(req,res){
  var myreq = https.request(options, function(res){
      console.log('Status: '+res.statusCode);
      console.log('Headers: '+JSON.stringify(res.headers));
      res.setEncoding('utf8');
      res.on('data', function(body){
          console.log("Body: "+body);
      });
  });
  myreq.on('error', function(e){
      console.log("Error!: "+e);
  })
  
  myreq.end();
  
  });
  
  // https.get("https://Client-ID:"+imgurClientID+"@api.imgur.com/3/gallery/search?q=yellow", function(res){
  //     res.setHeader("Client-ID", imgurClientID);
  //     var body = "";
  //     res.on('data', function(chunk){
  //         body+=chunk;
  //     });
  
  //     res.on('end', function(){
  //         var imgurRes = JSON.parse(body);
  //         console.log(imgurRes);
  //     });
  // }).on('error', function(e){
  //     console.log("Error!: "+e);
  // })
  
  app.get('/new/:name*', function(req,res){
      //detect if name is a URL
      //if it is not a proper http, return 'could not load' status
      if (req.params.name.substr(0,4).toLowerCase() != "http")
          {
          mystatus = "Could not load";
          res.json({url_part1: req.params.name,
                   url_part2: req.params[0],
                   status: mystatus
              });
  
          }
      http.get(req.params.name+req.params[0], function(thisres){
          var wwwpath = req.params[0].substr(2, req.params[0].length-2);
  
          //do not look for the site unless it returns a 200 status code
          if (thisres.statusCode != 200){
              loadstatus = "Could not load";
          }
  
          //otherwise, find the site in the MongoDB list!
          else {
              //indicate that the site is a working URL
              loadstatus = "Loaded!";
  
              //prepare the database
              mongo.connect("mongodb://dickorydock:$iderHouseRul3z@ds145365.mlab.com:45365/urlrosetta", function(err, db) {
                  var shorturl = db.collection("shorturl");
                  //find maximum site number
                  shorturl.find().sort({site_number:-1}).limit(1).toArray(function(err,documents){
                      max_site_number = documents[0]["site_number"];
                  })
                  //look for the site in the existing database
                  shorturl.find(
                     {original_url: wwwpath}
                   , {_id: 0, original_url: 1,short_url: 1, site_number:1})
                  .toArray(function(err,documents){    
                      //if we found it, no need to add it again -- just return the existing site number
                      if (documents.length&gt;0){
                          var sitenumber = documents[0]["site_number"];
                      }
                      //if we didn't find the working URL, add it
                      else {
                          var sitenumber = max_site_number + 3;
                          var newsitejson={original_url: wwwpath, site_number: sitenumber}
                          shorturl.insert(newsitejson)
                      }
  
                      //return the info about the short link
                      res.json({original_url:  req.params.name+"://"+wwwpath,
                          short_url: "http://dickorydock-shorturl.herokuapp.com/"+sitenumber
                          });
                    db.close()
                  })
              })
          }
  
      })
      //if there is an error in finding the site in the URL, return 'could not load' status
      .on('error', function(e){
          console.error(e.code);
          res.json({error: "Not a valid URL - try again."})          
      })
  })
  
  
  app.get('/:shortnum*', function(req,res){
     var sitenumber = parseInt(req.params.shortnum);
     var siteextra = req.params[0];
     if (siteextra.length &gt; 0){
          res.json({error: "Not a valid reference - try again."})
     }
     else {
      mongo.connect("mongodb://dickorydock:$iderHouseRul3z@ds145365.mlab.com:45365/urlrosetta", function(err, db) {
          var shorturl = db.collection("shorturl");
          //look for the site in the existing database, and either redirect or give an error
          shorturl.find(
             {site_number: sitenumber}
           , {_id: 0, original_url: 1, site_number:1})
          .toArray(function(err,documents){ 
              if (documents.length&gt;0){
              res.redirect("http://"+documents[0]["original_url"])
              }
              else if (documents.length == 0){
                  res.json({error: "Not a valid reference - try again."})
              }
            db.close()
           })
  
      })
  
      }
  
  })
  app.listen(8080, function(){
  //app.listen(process.env.PORT, function(){
      console.log("App listening")
  });
  </code></pre>