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

generate-certs

v3.0.0

Published

πŸ—οΈ Effortless HTTPS Certificate Generation for Local Development

Readme

Not for production. These are self-signed certificates for local development only. For production, use a trusted CA like Let's Encrypt.

Highlights ✨

  • Automatic certificate generation β€” no OpenSSL needed
  • Intelligent reuse β€” validates expiry, permissions, and key/cert pairing
  • Pre-configured for localhost β€” 127.0.0.1, ::1, and localhost SANs
  • Framework-ready β€” Express, NestJS, Hono, Fastify
  • Secure file permissions enforced (Unix: 600 on private key)

Installation πŸ“¦

Requires Node.js >= 18. Recommended as a dev dependency.

npm install -D generate-certs
# or
pnpm add -D generate-certs

Quick Start πŸš€

import path from "node:path";
import https from "node:https";
import express from "express";
import { generateCerts } from "generate-certs";

const certs = generateCerts({ certsPath: path.resolve(import.meta.dirname, "../certs") });

const app = express();
https.createServer(certs, app).listen(3443);

API Reference πŸ“–

generateCerts(options): { key: string; cert: string }

Generates or retrieves self-signed certificates from the specified directory. If valid certificates already exist, they are reused. Returns { key: string; cert: string } as PEM-formatted strings, ready for https.createServer().

import path from "node:path";
import { generateCerts } from "generate-certs";

// Auto-generates key.pem and cert.pem (or reuses valid existing ones)
const certs = generateCerts({ certsPath: path.resolve(import.meta.dirname, "../certs") });
console.log(certs.key); // "-----BEGIN RSA PRIVATE KEY-----\n..."
console.log(certs.cert); // "-----BEGIN CERTIFICATE-----\n..."

// Suppress console logs in CI/test environments
const silent = generateCerts({
  certsPath: path.resolve(import.meta.dirname, "../certs"),
  activateLogs: false,
});

Options: certsPath (required, absolute path to certificates directory), activateLogs (default true).

Throws if the path is invalid, inaccessible, or certificate generation fails.

Certificate Details πŸ“œ

| Property | Value | | ----------------------- | ------------------------------- | | Key algorithm | RSA 2048-bit | | Signature | SHA-256 | | Validity | 1 year from generation | | Common Name | localhost | | Subject Alt Names | localhost, 127.0.0.1, ::1 | | Private key permissions | 600 (Unix only) |

Smart Reuse ♻️

When certificates already exist at the specified path, the following checks are performed before reusing them:

  1. File existence β€” both key.pem and cert.pem must be present
  2. Permissions β€” private key must have 600 permissions (Unix only, skipped on Windows)
  3. Expiry β€” certificate must not be expired or expiring within 5 minutes
  4. Not-before β€” certificate must already be valid (not issued for the future)
  5. Common Name β€” must be localhost
  6. SANs β€” must include localhost, 127.0.0.1, and ::1
  7. Key size β€” RSA key must be at least 2048-bit
  8. Key/cert pairing β€” the private key must match the certificate's public key

If any check fails, certificates are automatically regenerated.

Framework Examples 🧩

NestJS

import path from "node:path";
import { NestFactory } from "@nestjs/core";
import { generateCerts } from "generate-certs";
import { AppModule } from "./app.module";

const certs = generateCerts({ certsPath: path.resolve(import.meta.dirname, "../certs") });

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { httpsOptions: certs });
  await app.listen(3443);
}

bootstrap();

HonoJS

import { createSecureServer } from "node:http2";
import path from "node:path";
import { serve } from "@hono/node-server";
import { generateCerts } from "generate-certs";
import { Hono } from "hono";

const certs = generateCerts({ certsPath: path.resolve(import.meta.dirname, "../certs") });

const app = new Hono();

serve({
  fetch: app.fetch,
  port: 3443,
  createServer: createSecureServer,
  serverOptions: certs,
});

Fastify

import path from "node:path";
import Fastify from "fastify";
import { generateCerts } from "generate-certs";

const certs = generateCerts({ certsPath: path.resolve(import.meta.dirname, "../certs") });

async function bootstrap() {
  const app = Fastify({ https: certs });
  await app.listen({ port: 3443, host: "0.0.0.0" });
}

bootstrap();

Best Practices βœ…

  • Add certs/ to .gitignore β€” never commit generated certificates to version control
  • Install as a dev dependency (-D) β€” this package is not needed in production
  • Browser warnings are expected β€” self-signed certificates will show "Not Secure"; click Advanced β†’ Proceed to localhost
  • Suppress logs with activateLogs: false when running in CI or test environments

Windows: File permission checks are skipped on Windows. Lock file stale detection uses a 60-second timeout as a cross-platform fallback.

Type Exports 🏷️

import type { GenerateCertsOptions } from "generate-certs";

Credits πŸ™

Built on node-forge for RSA key generation and X.509 certificate creation.

Contributions 🀝

  • Open an issue or feature request
  • Submit a PR to improve the package
  • Star the repo if you find it useful

Crafted carefully by WolfieLeader

This project is licensed under the MIT License.