ERR_SSL_PROTOCOL_ERROR browser error message while running a https server in nodejs express
Problem
I have a number of nodejs applications running on Express using the code below. They all run fine using code similar to the following:
fs = require 'fs'
https = require 'https'
express = require 'express'
server_port = 3000
keys_dir = 'keys/' server_options = {
key : fs.readFileSync(keys_dir + 'privatekey.pem'),
cert : fs.readFileSync(keys_dir + 'certificate.pem') } app = express.createServer(server_options)
app.listen server_port
console.log "HTTPS Server started on port #{server_port}"
However, when trying to create a new application using this code I see a ERR_SSL_PROTOCOL_ERROR when starting the Https Server. Any idea what is causing this problem?
Solution
I discovered that was caused when moving from express 2.5.8 to express 3 - specifically 3.0.0beta4. When creating a new project the version pulled from npm had changed to the version 3 series. Even though the module is marked as "beta" when you run express --version
this version is what is installed now when running npm install express
. The details of the changes are outlined here.
To solve this for my case I used the following code:
fs = require 'fs'
https = require 'https'
express = require "express"
server_port = 3000
keys_dir = 'keys/'
server_options = {
key : fs.readFileSync(keys_dir + 'privatekey.pem'),
ca : fs.readFileSync(keys_dir + 'certrequest.csr'),
cert : fs.readFileSync(keys_dir + 'certificate.pem')
}
app = express()
https.createServer(server_options,app).listen(server_port)
Discussion
View additional discussion.