Skip to content

Instantly share code, notes, and snippets.

@vukhanhtruong
Last active September 4, 2020 04:05
Show Gist options
  • Save vukhanhtruong/dbbcc4d5618975f4ffd676aa3b9e084e to your computer and use it in GitHub Desktop.
Save vukhanhtruong/dbbcc4d5618975f4ffd676aa3b9e084e to your computer and use it in GitHub Desktop.
ExpressJS Local SSL

Generate SSL by mkcert

mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1

Update express server

const key = fs.readFileSync("./ssl/localhost-key.pem");
const cert = fs.readFileSync("./ssl/localhost.pem");
const app = express();
const secureServer = https.createServer({ key: key, cert: cert }, app);

app.get("/", (req, res) => {
  res.send("Hello world!");
});

secureServer.listen(3000, "localhost", (err) => {
  if (err) throw err;
  console.log(`> Live @ https://localhost:3000`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment