Let's say for example the CertBot generated the SSL certificate and SSL certificate key to the following locations:
/etc/letsencrypt/live/example.org/fullchain.pem
/etc/letsencrypt/live/example.org/privkey.pem
After you have generated your certificate and key, you'll need to utilize the https
module directly.
You'll first need to export your Express app:
const express = require('express')
const path = require('path')
const port = process.env.PORT || 80
const app = express()
app.use(express.static(__dirname + '/build'))
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'build', 'index.html'))
})
module.export = app
Then simply import your Express app and hook it up with the https
module:
const https = require('https');
const fs = require('fs');
const app = require('./app.js');
const server = https.createServer({
key: fs.readFileSync('/etc/letsencrypt/live/example.org/fullchain.pem', 'utf8'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.org/privkey.pem', 'utf8')
}, app);
server.listen(3000);
Note this essentially what ./bin/www
does for you except I've adapted it to use https
instead of http
module.
See What does "./bin/www" do in Express 4.x?