← Back to archive

Repo of the Day

davewasmer/devcert

Published: Sep 30, 2021

Open repository ↗

Get a SSL cert for your local development node server

Summary

devcert is a TypeScript library that issues locally-trusted HTTPS certificates for development. On first run it creates a root certificate authority, installs it into OS and browser trust stores, and then signs certificates on demand so local servers load without browser warnings. The whole interaction is a single async call that returns the key and cert your server needs.

What it is useful for

devcert is useful when you need to run a local HTTPS server and don't want to deal with self-signed certificate warnings or manual CA setup. It works for single-host dev (e.g. my-app.test) and multi-tenant apps via the Subject Alternative Name extension, where one certificate covers several local domains like local.api.example.com, local.example.com, and local.auth.example.com. It also helps in Docker-based local setups, where you generate certs once in a shared folder and copy the resulting tls.key and tls.cert files into each project.

How engineers can use it

The documented entry point is await devcert.certificateFor(domain), or pass an array of domains for SAN. Pass the returned key and cert straight into Node's https.createServer, or use them with webpack-dev-server's https block. Certificates are cached by name, so repeated calls return the same material.

A few caveats from the README: devcert registers its CA with OS keychains, but some clients (Firefox, Node itself) use their own trust stores. For those, set getCaPath: true to get a caPath you can hand to NODE_EXTRA_CA_CERTS, or getCaBuffer: true to get the raw ca bytes. If you request a non-localhost domain, devcert edits /etc/hosts to point it at your machine; pass skipHostsFile: true to skip that step, but you'll then need some other DNS redirect.

Two more documented limitations: devcert normally installs certutil automatically (needed by Chrome on Linux and Firefox). Passing skipCertutil: true disables that, which breaks Chrome on Linux entirely and forces a one-time Firefox import wizard. The library also exposes a ui option for tools that want to brand or localize the prompts. The README does not include explicit install commands, so refer to the package for setup. License is MIT.