Socket
Book a DemoInstallSign in
Socket

generate-certs

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-certs

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

2.1.0
latest
Source
npmnpm
Version published
Weekly downloads
342
-67.89%
Maintainers
1
Weekly downloads
Β 
Created
Source
banner

generate-certs

Effortless HTTPS certificate generation
for local development environments.

License npm version npm downloads stars

About πŸ“–

generate-certs is a simple and developer-friendly utility for generating self-signed HTTPS certificates during local development.

It streamlines the process of creating key.pem and cert.pem files, supports both CommonJS and ES Modules, and integrates seamlessly into frameworks like Express and NestJS.

Features πŸ’‘

  • πŸ” Automatic Certificate Generation – Creates valid self-signed certificates for localhost.
  • πŸ” Reusability – Automatically detects and reuses existing certs if they exist.
  • πŸ§ͺ Development-Ready – Ideal for testing HTTPS locally without browser complaints.
  • πŸ’‘ Minimal Setup – No OpenSSL or third-party installations required.
  • 🧩 Framework Friendly – Easily integrates with Express, NestJS, and other Node.js frameworks.
  • βš™οΈ Type-Safe & Cross-Compatible – Fully written in TypeScript with native types. Works in both ESM and CommonJS runtimes.

Installation πŸ”₯

npm install -D generate-certs@latest

πŸ’‘ Works with npm, pnpm, and yarn. You can use it in dev dependencies since it's typically used only for local HTTPS.

Usage πŸͺ›

Basic Example 🐣

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { generateCerts } from 'generate-certs';

// If you are using ESM do the following, otherwise you can skip this part
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const certs = generateCerts({ certsPath: path.resolve(__dirname, '../certs') });

Express πŸ“«

import https from 'node:https';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { generateCerts } from 'generate-certs';
import express from 'express';
import { env } from './env';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const certs = generateCerts({ certsPath: path.resolve(__dirname, '../certs') });

function bootstrap() {
  const app = express();

  https.createServer(certs, app).listen(env.PORT || 3443, () => {
    console.log(`πŸš€ Express server running on: https://localhost:${env.PORT || 3443}`);
  });
}

bootstrap();

NestJS πŸͺΊ

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

// NestJS commonly uses CommonJS, so you can skip the ESM import part
const certs = generateCerts({ certsPath: path.resolve(__dirname, '../certs') });

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

  await app.listen(env.SERVER_PORT || 3443);
  console.log(`πŸš€ NestJS server running on: https://localhost:${env.SERVER_PORT || 3443}`);
}

bootstrap();

HonoJS πŸ”₯

import { createSecureServer } from 'node:http2';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { serve } from '@hono/node-server';
import { generateCerts } from 'generate-certs';
import { Hono } from 'hono';
import { env } from './env';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const certs = generateCerts({ certsPath: path.resolve(__dirname, '../certs') });

function bootstrap() {
  const app = new Hono();

  serve(
    {
      fetch: app.fetch,
      port: env.PORT || 3443,
      createServer: createSecureServer,
      serverOptions: certs,
    },
    (info) => {
      console.log(`πŸš€ HonoJS server running on: https://localhost:${env.PORT || 3443}`);
    },
  );
}

bootstrap();

Fastify ⚑

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import Fastify from 'fastify';
import { generateCerts } from 'generate-certs';
import { env } from './env';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const certs = generateCerts({ certsPath: path.resolve(__dirname, '../certs') });

async function bootstrap() {
  const app = new Fastify({ https: certs });

  await app.listen({ port: env.PORT || 3443, host: '0.0.0.0' });
  console.log(`πŸš€ Fastify server running on: https://localhost:${env.PORT || 3443}`);
}

bootstrap();

Notes❗

  • πŸ§ͺ First-Time Run: The certs are created automatically and stored in the provided folder.
  • ⚠️ Browser Warnings: You may see β€œNot Secure” warnings with self-signed certs β€” click β€œAdvanced” β†’ β€œProceed to localhost (unsafe)” to continue.
  • πŸ”’ Not for Production: These are local dev certificates. For production, use certs from a trusted CA (like Let's Encrypt).
  • πŸ“ Permissions: Ensure the target folder is writable and readable by your application.

Contributions 🀝

Want to contribute or suggest a feature?

  • Open an issue or feature request
  • Submit a PR to improve the packages or add new ones
  • Star ⭐ the repo if you like what you see

License πŸ“œ

This project is licensed under the MIT License.

Thank you!

Keywords

https

FAQs

Package last updated on 21 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.