Last Updated: December 07, 2017
·
8.363K
· milesmatthias

creating a nodejs express https server

I searched for a while and found a lot of out dated articles and stack overflow suggestions until I found a post that gave me the solution:

var express = require('express')
  , fs = require('fs')
  , https = require('https')

var httpsOptions = {
    key: fs.readFileSync('path/to/key')
      , cert: fs.readFileSync('path/to/cert')
}

var app = express.createServer()
    , appSecure = express.createServer(httpsOptions)

app.listen(80)
appSecure.listen(443)

1 Response
Add your response

Thank you. I implemented the equivalent of this, and for a still-undiagnosed reason it fails to complete a connection. The certificate-key configuration works with Nginx, but not with Node/Express. Running
openssl s_client -connect jpdev.pro:3000 -showcerts -prexit -state -debug -msg
on a client, I get a lot of output, of which the piece that seems most informative is:
SSL_connect:failed in SSLv3 read finished A 51684:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-64.50.6/src/ssl/s23_lib.c:185:

over 1 year ago ·