title: How to get data from REST api using an API key in node js?
body: <p>I am using a 3rd party REST API in my node server. The 3rd party API provider as given me an API key and an example in cURL as follows:</p>
  
  <pre><code>$ curl -u APIKey@https://xyzsite.com/api/v1/users
  </code></pre>
  
  <p>I am not sure how I do it in node js. I have tried following but no luck. I get</p>
  
  <pre><code>var options = {
    host: "xyzsite.com",
    path: "/api/v1/users",
    headers: {
      "Authorization": "Basic " + myAPIKey
    }
  };
  
  
  https.get(options, function(res, error) {
    var body = "";
    res.on('data', function(data) {
      body += data;
    });
    res.on('end', function() {
  
      console.log(body);
    });
    res.on('error', function(e) {
      console.log(e.message);
    });
  });
  </code></pre>
  
  <p>Console message</p>
  
  <pre><code>{
    "message": "No authentication credentials provided."
  }
  </code></pre>