3

I'm pretty much following this tutorial (all other tutorials I found look the same)

http://www.hacksparrow.com/express-js-https.html

My code is as follows:

// dependencies
var express = require('express')
  , https = require('https')
  , fs = require('fs');

var privateKey = fs.readFileSync('./ssl/rp-key.pem').toString();
var certificate = fs.readFileSync('./ssl/rp-cert.pem').toString();

var app = express.createServer({
  key : privateKey
, cert : certificate
});

...

// start server
https.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

The app starts fine after sudo node app

Express server listening on port 443

Now when I curl

curl https://localhost/

I get

curl: (35) Unknown SSL protocol error in connection to localhost:443

Any ideas?

3
  • Do you get the same error if you remove the calls to toString on the key and cert? Commented Jul 19, 2012 at 19:17
  • ya, i get the same error after removing toString Commented Jul 19, 2012 at 19:23
  • Have answered this succinctly here: stackoverflow.com/a/23894573/1882064 Commented Oct 9, 2014 at 15:29

1 Answer 1

3

Since Express 3.x, which is now being published via npm, the "app()"-Application Function changed. There is an migration info on https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x . None of the express 2.x SSL tutorials will work anymore. The correct Code for express 3.x is:

// dependencies
var express = require('express')
  , https = require('https')
  , fs = require('fs');

var privateKey = fs.readFileSync('./ssl/rp-key.pem').toString();
var certificate = fs.readFileSync('./ssl/rp-cert.pem').toString();

var options = {
  key : privateKey
, cert : certificate
}
var app = express();

...

// start server
https.createServer(options,app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});
Sign up to request clarification or add additional context in comments.

5 Comments

https.createServer part was generated by express; it was http.createServer(app).listen ... by default; lemme try that though
It must be your key/certs then. How do you create them?
i just followed the tutorial exactly
when generating the certrequest, i left a few questions empty, would that cause an issue?
I edited my post, check github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x (Application Function) for more info. I think this will be a popular question in the future ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.