Tag Archives: express

Using mkcert to create locally-trusted development certificates.

mkcert git repo

Creating certificate files

  1. Navigate to desired location where the certificate will be created (for example $ mkdir local-ssh-certificates;cd local-ssh-certificates )
  2. Install mkcert tool: $ brew install mkcert
  3. Generate certificates for localhost : $ mkcert localhost
  4. Install local CA in the system thrust store (this does not work for Firefox) mkcert -install

Setting up Express server to use certificates

Make sure to replace /Users/toni/local-ssh-certificates with your real location.

var express = require('express');
var https = require('https');
var app = express();
const path = require('path');
const fs = require('fs');


app.use(express.static('src'))



  https.createServer({ 
    // replace with certificate location
    key: fs.readFileSync('/Users/toni/local-ssh-certificates/localhost-key.pem'),
    cert: fs.readFileSync('/Users/toni/local-ssh-certificates/localhost.pem')
  }, app).listen(5001);
  console.log('App listening on port 5001!');