Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.02 KB

secureserver.md

File metadata and controls

28 lines (19 loc) · 1.02 KB

Using HTTPS to encrypt the client-server connection



One Paragraph Explainer

Using services such as Let'sEncrypt, a certificate authority which provides free SSL/TLS certificates, can help encrypt the communication of your applications. Node.js frameworks like Express (based on the core https module) support SSL/TLS, which can be implemented in a few lines of code.

You can also configure SSL/TLS on a reverse proxy, such as NGINX or HAProxy.



Code Example – Enabling SSL/TLS using the Express framework

const express = require('express');
const https = require('https');
const app = express();
const options = {
    // The path should be changed accordingly to your setup
    cert: fs.readFileSync('./sslcert/fullchain.pem'),
    key: fs.readFileSync('./sslcert/privkey.pem')
};
https.createServer(options, app).listen(443);