Skip to content

Instantly share code, notes, and snippets.

@hicaro
Last active November 14, 2020 15:59
Show Gist options
  • Save hicaro/fcd96d1995e8fabe3544c83212b4f5fa to your computer and use it in GitHub Desktop.
Save hicaro/fcd96d1995e8fabe3544c83212b4f5fa to your computer and use it in GitHub Desktop.
SSL Certificate in express app
const https = require("https");
const fs = require("fs");
const express = require("express");
// read keys
const key = fs.readFileSync("localhost.key");
const cert = fs.readFileSync("localhost.crt");
// create express app
const app = express();
// create a HTTPS server
const server = https.createServer({ key, cert }, app);
// add test route
app.get("/", (req, res) => {
res.send("this is an secure server");
});
// start server on port 8000
server.listen(8000, () => {
console.log("listening on 8000");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment