title: How do you fix "self signed certificate in certificate chain" error with Node.js?
body: <p>I currently have an application that runs partially on Node.js/Electron (backend) and React (frontend). I am able to run these separately but the full project has to utilize both. Usually, the javascript code for the backend heavily utilized <code>http.get</code> calls. </p>
  
  <p>Recently, I set up a TSL/SSL certificate such that only trusted users could see/access certain aspects of the application. After this, I tried to change all my <code>http.get</code> calls into <code>https.get</code> calls and all of my relevant endpoints from <code>http://</code> into <code>https://</code>. All was working fine up until I made this change. While changing the URLs didn't seem to change anything, changing the <code>http.get</code> requests to <code>https.get</code> requests did.</p>
  
  <p>Now, I keep getting the error <code>Error: self signed certificate in certificate chain</code> and I'm not entirely sure how to fix this. It seems to work everywhere except for Node. I don't want it to change the code to allow unauthorized users. I just want to make sure the data I'm sending and receiving is encrypted.</p>
  
  <p>I've tried to use Node's <code>node-rest-client</code> but I don't think that this resolves the issue either. I've been trying to use Wireshark to validate whether my data is encrypted or not, but I'm not sure that that is getting me any closer to a solution either.</p>
  
  <p>My code looks like the following:</p>
  
  <pre><code>const path = require('path')
  const https = require('https')
  
  async function foobar1 (options) {
    return new Promise(async (resolve, reject) =&gt; {
      await https.get(options, async (response) =&gt; {
        console.log(response)
      }).on('error', function (e) {
        reject(new Error(e, e.message))
      })
    })
  }
  </code></pre>
  
  <p>where <code>options</code> looks like: <code>{ hostname: 'hostname', path: '/path', headers: { ApiKey: '????-????-????'} }</code></p>