title: Node.js https pem error: routines:PEM_read_bio:no start line
body: <p>I am messing with login form right now with node.js, I tried creating a pem key and csr using </p>
  
  <pre><code>openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
  </code></pre>
  
  <p>However I been getting errors for running node server.js</p>
  
  <p>Here is my server.js</p>
  
  <pre><code>var http = require('http'),
      express = require('express'),
  UserServer = require('./lib/user-server');
  
  var https = require('https');
  var fs = require('fs');
  
  var options = {
    key: fs.readFileSync('./key.pem', 'utf8'),
    cert: fs.readFileSync('./csr.pem', 'utf8')
  };
  
  var app = express();
  
  app.configure(function(){
    app.use(express.bodyParser());
    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
  });
  
  var httpserver = http.createServer(app).listen('3004', '127.0.0.1');
  var https_server = https.createServer(options, app).listen('3005', '127.0.0.1');
  UserServer.listen(https_server);
  </code></pre>
  
  <p>Here is the error</p>
  
  <pre><code>crypto.js:104
    if (options.cert) c.context.setCert(options.cert);
                            ^
  Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
      at Object.exports.createCredentials (crypto.js:104:31)
      at Server (tls.js:1107:28)
      at new Server (https.js:35:14)
      at Object.exports.createServer (https.js:54:10)
  </code></pre>
  
  <p>I tried running </p>
  
  <pre><code>openssl x509 -text -inform DER -in key.pem
  </code></pre>
  
  <p>It gives</p>
  
  <pre><code>unable to load certificate
  140735208206812:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
  140735208206812:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=X509
  </code></pre>
  
  <p>I am not exactly sure what does the error mean as my encryption file is .pem file already, so any help would be much appreciated.</p>
  
  <p>Thanks</p>