Last active
February 5, 2021 21:19
-
-
Save alvinslee/a735eb91f0fd312a92fdb1390156471e to your computer and use it in GitHub Desktop.
Node.js Express Server served with HTTPS using localhost certificate
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 fs = require('fs') | |
const key = fs.readFileSync('./localhost/localhost.decrypted.key') | |
const cert = fs.readFileSync('./localhost/localhost.crt') | |
const express = require('express') | |
const app = express() | |
app.get('/', (req, res, next) => { | |
res.status(200).send('Hello world!') | |
}) | |
const https = require('https') | |
const server = https.createServer({ key, cert }, app) | |
const port = 3000 | |
server.listen(port, () => { | |
console.log(`Server is listening on https://localhost:${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment