title: Node.js https pem error: error:0906D06C:PEM routines:PEM_read_bio:no start line
body: <p>I got these files from the Certificate Authority:</p>
  <ul>
  <li>domain.com.p7b</li>
  <li>domain.com.crt</li>
  <li>domain.com.ca-bundle</li>
  </ul>
  <p>And I tried this little code:</p>
  <pre><code>var express = require('express');
  var app = express();
  var fs = require(&quot;fs&quot;);
  var https = require('https');
  
  var privateKey = fs.readFileSync('domain.com.p7b').toString();
  var certificate = fs.readFileSync('domain.com.crt').toString();
  var ca_bundle = fs.readFileSync('domain.com.ca-bundle').toString();
  
  var credentials = { key: privateKey, 
                      ca : ca_bundle,
                      cert: certificate};
                                      
  
  https.createServer(credentials,app).listen(8080, function () {
      console.log('Example app listening on port 8080!');
  });
  </code></pre>
  <p>After start script, I get the following error:</p>
  <pre><code>(err):     at Object.createSecureContext (_tls_common.js:87:19)
  (err):     at Server (_tls_wrap.js:721:25)
  (err):     at new Server (https.js:17:14)
  (err):     at Object.exports.createServer (https.js:37:10)
  (err):     at Object.&lt;anonymous&gt; (/utec_temp/https/web.js:27:7)
  (err):     at Module._compile (module.js:435:26)
  (err):     at Object.Module._extensions..js (module.js:442:10)
  (err):     at Module.load (module.js:356:32)
  (err):     at Function.Module._load (module.js:311:12)
  (err): Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
  (err):     at Error (native)
  (err):     at Object.createSecureContext (_tls_common.js:87:19)
  (err):     at Server (_tls_wrap.js:721:25)
  (err):     at new Server (https.js:17:14)
  (err):     at Object.exports.createServer (https.js:37:10)
  (err):     at Object.&lt;anonymous&gt; (/utec_temp/https/web.js:27:7)
  (err):     at Module._compile (module.js:435:26)
  (err):     at Object.Module._extensions..js (module.js:442:10)
  (err):     at Module.load (module.js:356:32)
  (err):     at Function.Module._load (module.js:311:12)
  </code></pre>
  <p>All the examples on google uses self-signed certificates , but what happen when I need to work in a real environment?</p>
  <p>My little code works in development with self signed keys , following this example:</p>
  <ul>
  <li><a href="https://stackoverflow.com/a/24283204/3957754">https://stackoverflow.com/a/24283204/3957754</a></li>
  </ul>
  <p>I researched and I found this:</p>
  <ul>
  <li><a href="https://www.namecheap.com/support/knowledgebase/article.aspx/9705/0/nodejs" rel="nofollow noreferrer">https://www.namecheap.com/support/knowledgebase/article.aspx/9705/0/nodejs</a></li>
  <li><a href="http://www.backwardcompatible.net/155-Setting-up-real-SSL-Nodejs-Express" rel="nofollow noreferrer">http://www.backwardcompatible.net/155-Setting-up-real-SSL-Nodejs-Express</a></li>
  <li><a href="https://stackoverflow.com/questions/22584268/node-js-https-pem-error-routinespem-read-biono-start-line">Node.js https pem error: routines:PEM_read_bio:no start line</a></li>
  </ul>
  <p>but I could not correct the error.</p>
  <p>Also I reduced to one file :</p>
  <pre><code>var credentials = {cert: certificate};      
  </code></pre>
  <p>And the error is the same. So I thought that maybe is a format error when I move these certificates from windows to unix. I used dos2unix tool and the error is the same.</p>
  <p>My node version is 4.4.7</p>
  <p>Any help is appreciated.</p>
  <p>Thanks in advance!</p>