NODEJS Contents

HTTPS/TLS Basics for Backend Devs

Understand TLS fundamentals and when to terminate HTTPS at Node versus a reverse proxy.

On this page

HTTPS and TLS

The https module wraps HTTP with TLS encryption. In production, TLS may be terminated at a load balancer or directly inside Node.

import https from 'https';
import fs from 'fs';

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options, (req, res) => {
  res.end('secure');
}).listen(443);

Architectural Decision

Terminating TLS at a reverse proxy improves scalability. Direct TLS in Node is common for smaller deployments or internal services.