Charlie Fish Charlie Fish - 1 year ago 119
Node.js Question

Express.js HTTPS not starting server

I'm trying to configure HTTPS for my Express server. I found the following code from this question's answers.

console.log("Test 1");
var httpServer = http.createServer(app);
console.log("Test 2");
var httpsServer = https.createServer(credentials, app);
console.log("Test 3");
console.log("Test 4");
console.log("Test 5");

Problem is the only thing that appears in the console is
Test 1
Test 2
. Nothing after that line seems to be running. I basically just want the same Express app to run on both HTTP and HTTPS.

In the past I just used
server = app.listen(port);
to start the Express server.

Any ideas?


The Node app continues to run with no errors but just doesn't print those final

var fs = require('fs');
var privateKey = fs.readFileSync('ssl/servertest.key', 'utf8');
var certificate = fs.readFileSync('ssl/servertest.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};

servertest.key and servertest.crt.

Note: I know putting those online and making them public is a bad idea. Just using it for example. Before going into production I'm going to regenerate the SSL keys.

Answer Source

Yes, the private key was password protected.

On my system I was getting the error,

Error: error:0906A068:PEM routines:PEM_do_header:bad password read

not sure why you wasn't, maybe it's node version.

Here you have 2 options, either remove the password from the key using openSSL, or supply the password to the options via the passphrase option.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download