3

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?

1 Answer 1

1

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:

const fs = require("fs");
const https = require("https");
const express = require("express");

const keysDir = "keys/";
const options = {
  key  : fs.readFileSync(keysDir + "privatekey.pem"),
  ca   : fs.readFileSync(keysDir + "certrequest.csr"),
  cert : fs.readFileSync(keysDir + "certificate.pem")
};

const app = express();
https.createServer(options, app).listen(3000);
Sign up to request clarification or add additional context in comments.

1 Comment

can you understand what's the difference? the added ca? how did that help?

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.