npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

postgres-self-cert-ssl

v1.0.1

Published

Enable and maintain SSL for local PostgreSQL on macOS or Linux

Readme

postgres-self-cert-ssl

A Node.js CLI tool to enable and maintain SSL for a local PostgreSQL server (macOS & Linux).
It generates a self-signed certificate, updates Postgres configs, and restarts the service using the right method for your platform.

Perfect for local dev environments where you want ssl=on without messing around manually.


Features

  • 🔍 Detects running Postgres (socket or common TCP ports)
  • ⚡ Starts Postgres automatically (supports brew services on macOS, systemctl on Linux)
  • 📦 Auto-installs Postgres if missing (brew, apt, dnf, yum)
  • 🛠 Auto-initializes Homebrew clusters if the data dir is empty
  • 🔒 Generates or renews self-signed certs with proper permissions (server.key chmod 0600)
  • ✍️ Updates postgresql.conf (ssl=on, ssl_cert_file, ssl_key_file)
  • 📝 Optionally appends hostssl rules to pg_hba.conf
  • 🔄 Restarts Postgres with the right controller (brew services restart preferred on macOS, pg_ctl fallback)
  • 🗂 Backs up modified config files with .bak timestamps
  • 🧪 Includes --check-only mode to view status without making changes

Install

Global CLI (recommended)

npm i -g postgres-self-cert-ssl

Now run:

postgres-self-cert-ssl --help

Local project devDependency

npm i -D postgres-self-cert-ssl

Then add to your package.json:

{
  "scripts": {
    "pg:ssl": "postgres-self-cert-ssl"
  }
}

Run with:

npm run pg:ssl -- --check-only

Usage

postgres-self-cert-ssl [options]

Options

--check-only            Print current SSL and cert status then exit
--force                 Regenerate certs even if valid
--renew-days=N          Renew if cert expires within N days (default 30)
--cert-days=N           Validity period for new certs in days (default 3650)
--update-hba            Add hostssl rules to pg_hba.conf (127.0.0.1 and ::1)
--no-restart            Skip restarting PostgreSQL after changes
--auto-start            Start PostgreSQL automatically if it is not running
--auto-install          Install PostgreSQL automatically if it is missing
--assume-yes            Noninteractive yes to prompts
--port-scan=CSV         Ports to scan, default 5432,5433,5434
--data-dir=PATH         Use this data dir when server is not reachable
--help, -h              Show usage

Environment

PGURL                   Optional libpq connection string passed to psql
                        Example: PGURL="host=localhost user=postgres"

Examples

Check SSL and cert status:

postgres-self-cert-ssl --check-only

Enable SSL and update pg_hba.conf:

postgres-self-cert-ssl --update-hba

Force fresh cert valid for one year:

postgres-self-cert-ssl --force --cert-days=365

Run noninteractive on a clean macOS dev machine:

postgres-self-cert-ssl --auto-install --auto-start --assume-yes

Operate offline against a known data dir:

postgres-self-cert-ssl --data-dir=/opt/homebrew/var/postgresql@14 --update-hba

What it changes

  • Creates or renews server.key and server.crt in your Postgres data directory
  • Sets server.key to 0600 permissions
  • Updates postgresql.conf with:
    • ssl = on
    • ssl_cert_file = 'server.crt'
    • ssl_key_file = 'server.key'
  • If --update-hba is passed, appends:
    • hostssl all all 127.0.0.1/32 md5
    • hostssl all all ::1/128 md5
  • Restarts Postgres via:
    • brew services restart postgresql@XX (macOS)
    • systemctl restart postgresql or pg_ctl (Linux)
  • Backups configs with .bak suffix and timestamp

macOS Homebrew notes

  • Prefers brew services restart when available
  • If a data dir exists but isn’t initialized, runs initdb for you
  • If restart hangs, try manually:
    brew services restart postgresql@14

Linux notes

  • Tries sudo systemctl start postgresql and common versioned unit names
  • If your distro uses a different unit, restart manually and rerun --check-only

Security

  • Self-signed certs are fine for local development
  • For production, replace server.crt and server.key with your CA-issued certs
  • Run with the user that owns your Postgres data dir (or sudo -u postgres on Linux)

Troubleshooting

  • `psql: could not connect`
    Postgres isn’t running or uses a nonstandard port. Try `--auto-start` or set `PGURL`.

  • `pg_ctl: server does not shut down` on macOS
    Launchd likely holds the service. Use `brew services restart postgresql@XX`.

  • Stale `postmaster.pid`
    If the file exists but no postgres process is running, remove it: ```bash rm -f /path/to/pgdata/postmaster.pid ```

  • Permission denied writing configs
    Run as the Postgres user or `sudo -u postgres`.


License

MIT