Adding HTTPS support to Notes

Now that we have a process to register with Let's Encrypt, and renew the SSL certificates we receive, let's look at adding HTTPS support to the Notes application. The task is fairly simple since the Node.js platform provides an HTTPS server alongside the HTTP server object we've used all along.

We'll require these changes to notes/app.mjs:

import http from 'http';import https from 'https';...const USEHTTPS = process.env.NOTES_USE_HTTPS          && (typeof process.env.NOTES_USE_HTTPS === 'string')          && (process.env.NOTES_USE_HTTPS === 'true');const CERTSDIR = process.env.NOTES_CERTS_DIR;const options = USEHTTPS ? {  key: fs.readFileSync(`${CERTSDIR}/privkey1.pem`),  cert: fs.readFileSync(`${CERTSDIR}/fullchain1.pem`), ca: ...

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.