Last active
November 14, 2020 15:59
-
-
Save hicaro/fcd96d1995e8fabe3544c83212b4f5fa to your computer and use it in GitHub Desktop.
SSL Certificate in express app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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