Answer the question
In order to leave comments, you need to log in
NodeJS Express SSL connection error?
Hello. I'm trying to run NodeJS with an SSL certificate. Code snippet
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const http = require('http');
const https = require('https');
const fs = require('fs');
// require our custom dependencies
const router = require('./router');
const PORT = process.env.PORT || 8000;
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(express.static(__dirname + '/../public'));
app.use(router);
//NOT WORK
if (process.env.PROD) {
const options = {
key: fs.readFileSync('path/to/private-key.key'),
cert: fs.readFileSync('path/to/cert.crt'),
// optional
ca: [
fs.readFileSync('path/to/COMODORSADomainValidationSecureServerCA.crt'),
fs.readFileSync('path/to/COMODORSAAddTrustCA.crt')
]
};
https.createServer(options, app).listen(PORT, function () {
console.log('PROD app listening on port', PORT);
});
}
// WORK
else {
http.createServer(app).listen(PORT, function () {
console.log('Example app listening on port', PORT);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question