I'm trying to use my purchased SSL certificate in Node.js - this certificate works perfectly in Nginx and Apache without any errors.

However, when I try to use it in Node.js, I get this error :

throw new Error('Missing PFX or certificate + private key.');
Error: Missing PFX or certificate + private key.
at Server (tls.js:1124:11)
at new Server (https.js:35:14)
at Object.exports.createServer (https.js:54:10)
at Object.<anonymous> (/usr/home/server.js:9:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)

Here is my server.js code :

var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('key.key'),
  cert: fs.readFileSync('cert.crt')

var server = https.createServer(function(req, res) {
  res.end('Hello Http\r\n');
server.listen(8080, '');

I noticed some examples require converting the .crt and .key to .pem format. I am able to convert the .crt file, but converting the .key file gives me this error:

[localhost ~]$ openssl x509 -in key.key -out key.pem -outform PEM
unable to load certificate
34379118248:error:0906D06C:PEM routines:PEM_read_bio:no start line:/usr/src/secure/lib/libcrypto/../../../crypto/openssl/crypto/pem/pem_lib.c:703:Expecting: TRUSTED CERTIFICATE

I am at loss on what to do next. As I mentioned earlier, this SSL certificate is currently installed and running on Nginx and Apache without any issues.

Any ideas what I can try next?

** SOLVED **

I just needed change the 'createServer' line to :

var server = https.createServer(options, function(req, res)

A private key is in RSA format, not X509. Use "rsa" instead of "x509" in your openssl conversion command.

| improve this answer | |
  • Thank you, I was able to convert the cert and key to .pem, but node is still throwing the error : Error: Missing PFX or certificate + private key. – Brian Smith Sep 12 '14 at 15:59
  • Solved - added solution to original question. – Brian Smith Sep 12 '14 at 21:30
  • by "rsa" do you mean genrsa? – AlexLordThorsen Apr 29 '16 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.