title: NodeJS 'DEPTH_ZERO_SELF_SIGNED_CERT'
body: <p>I get the above error when I try to connect to a webserver with a node.js client I am writing at te moment.</p>
  
  <p>But I get an error when I try to connect to the server.</p>
  
  <p><code>'DEPTH_ZERO_SELF_SIGNED_CERT'</code></p>
  
  <p>This is the code that sends the request. And turning off the certificate check is not a valid option. I need the connection to be secured. </p>
  
  <pre><code>var options = 
      {
          hostname: baseUri,
          port: 443,
          path: 'oauth',
          method: 'POST',
          requestCert: true,
          ca:fs.readFileSync('Comodo_PositiveSSL_bundle.crt'),
          rejectUnauthorized: true,
          headers: {
              //'User-Agent': USER_AGENT,
              'Content-Type': 'application/x-www-form-urlencoded',
              'Content-Length': data.length
          }
      };
  
      var req = http.request(options, (res) =&gt; {
        console.log('statusCode: ', res.statusCode);
        console.log('headers: ', res.headers);
  
        res.on('data', (d) =&gt; {
          process.stdout.write(d);
        });
      });
  
      req.write(data)
      req.end();
  
      req.on('error', (e) =&gt; {
        console.error(e);
      });
  </code></pre>
  
  <p>If someone can tell me how I can setup the certification correct so no error is generated?</p>
  
  <hr>
  
  <p>Picture of the cert bundle. As you can see the bundle contains only the root certificates need to verify the certificate the server provides itself.</p>
  
  <p><a href="https://i.stack.imgur.com/06YKY.png" rel="noreferrer"><img src="https://i.stack.imgur.com/06YKY.png" alt="Cert bundle"></a></p>