Skip to content

Instantly share code, notes, and snippets.

@alvinslee
Last active February 5, 2021 21:19
Show Gist options
  • Save alvinslee/a735eb91f0fd312a92fdb1390156471e to your computer and use it in GitHub Desktop.
Save alvinslee/a735eb91f0fd312a92fdb1390156471e to your computer and use it in GitHub Desktop.
Node.js Express Server served with HTTPS using localhost certificate
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