How to run node.js applications securely on a web server using letsencrypt certs that automatically renew?
We did follow several tutorials on creating certificates and included the appropriate paths to the .pem .cert and .key files which worked for a while until the certificate did not renew.
Our server setup is debian 12 using ispconfig hosting panel.
Eventually, we figured the best solution might be to use the LE certificate files created in the ssl folder of our website.
Check this test code and see if you can improve it or have other suggestions:
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var app = express();
var options = {
key: fs.readFileSync('/var/www/yourwebsite.tld/ssl/yourwebsite.tld-le.key'),
cert: fs.readFileSync('/var/www/yourwebsite.tld/ssl/yourwebsite.tld-le.crt')
};
// var options = {}
app.get('/', function(req, res){
res.send('Hello World!');
});
http.createServer(app).listen(8880, function(err){
if (err) console.log("Error in server setup")
console.log("http Server listening on Port", 8880);
})
https.createServer(options, app).listen(8843, function(err){
if (err) console.log("Error in server setup")
console.log("https Server listening on Port", 8843);
})