title: Node.js http post request with basic authentication
body: <p>I can make this work with axios but as I want to do this with default http module for some reasons</p>
  
  <p>Here is the code</p>
  
  <pre><code>var express = require("express");
  const http = require('https');
  var app = express();
  
  app.listen(3000, function () {
      var username = 'username';
      var password = 'password';
      var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
  
  const data = JSON.stringify({
      campaign_id: 'all',
      start_date: '01/01/2010',
      end_date: '05/31/2030',
      return_type: 'caller_view',
      criteria: {
          phone: 98855964562
      }
  });
  
  var hostName = "https://staging.crm.com";
  var path = "/api/v1/caller_find";
  
  const options = {
      hostName: hostName,
      path: path,
      port: 3000,
      method: 'POST',
      headers: {
          'Content-Type': 'application/json',
          'Authorization': auth,
          'Content-Length': data.length
      }
  };
  const req = http.request(options, (res) =&gt; {
      console.log('response is ' + res);
  });
  
  req.on('error', (error) =&gt; {
      console.log('error is ' + error);
    });
  });
  </code></pre>
  
  <p>But it is throwing exception </p>
  
  <blockquote>
    <p>connect ECONNREFUSED 127.0.0.1:443</p>
  </blockquote>