Last Updated: December 07, 2017
· 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)


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 -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/

over 1 year ago ·