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

mtls-universal-proxy

v1.0.10

Published

Zero-trust mTLS forward proxy server and client SDK for Node.js

Downloads

447

Readme

mtls-universal-proxy

Zero-trust Mutual TLS (mTLS) forward proxy server and promise-based client SDK for Node.js with zero external dependencies.

npm version license

mtls-universal-proxy makes it seamless to route HTTP/HTTPS traffic through a secure, encrypted mTLS tunnel. It provides both a robust proxy server that authenticates incoming client certificates and forwards requests to target URLs, and a lightweight, promise-based HTTP client SDK.


Features

  • 🔒 Zero-Trust Security: Enforces 2-way Mutual TLS (mTLS) authentication out of the box.
  • Zero External Dependencies: Built entirely on native Node.js core modules (https, http, fs, path).
  • 🚀 Full HTTP Parity: Supports all HTTP verbs (GET, POST, PUT, PATCH, DELETE), custom headers, query params, and binary streams.
  • 📦 Dual Module Support: Natively compatible with both CommonJS (require) and ES Modules (import).
  • 📘 TypeScript Ready: Complete TypeScript definition files (.d.ts) included out-of-the-box.
  • 🛠️ Flexibility: Load certificates via file paths or directly from memory Buffer objects.

Installation

npm install mtls-universal-proxy

🔑 Certificate Setup (Quick Start)

mTLS requires a Root Certificate Authority (CA) to sign both the server and client certificates.

Generate Certificates (Linux / Git Bash / PowerShell)

# 1. Create Root CA
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -out ca.crt \
  -subj "/C=US/ST=State/L=City/O=MyOrg/OU=CA/CN=MyProxyRootCA"

# 2. Server SAN Config (server.ext)
echo "authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
IP.1 = 127.0.0.1
DNS.1 = localhost" > server.ext

# 3. Create Server Cert
openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr -subj "/C=US/ST=State/L=City/O=MyOrg/OU=Server/CN=MyProxyServer"
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -sha256 -extfile server.ext

# 4. Create Client Cert
openssl genrsa -out client.key 2048
openssl req -new -key client.key -out client.csr -subj "/C=US/ST=State/L=City/O=MyOrg/OU=Client/CN=MyProxyClient"
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -sha256

🚀 Usage Guide

1. Starting the Proxy Server

const { MtlsProxyServer } = require('mtls-universal-proxy');

const server = new MtlsProxyServer({
  port: 7878,
  host: '0.0.0.0',
  key: './certs/server.key',
  cert: './certs/server.crt',
  ca: './certs/ca.crt',
});

server.listen().then(() => {
  console.log('mTLS Proxy Server running on port 7878');
}).catch((err) => {
  console.error('Failed to start proxy:', err);
});

2. Making Client Requests

const { MtlsProxyClient } = require('mtls-universal-proxy');

const client = new MtlsProxyClient({
  proxyHost: '127.0.0.1',
  proxyPort: 7878,
  key: './certs/client.key',
  cert: './certs/client.crt',
  ca: './certs/ca.crt',
});

async function run() {
  try {
    // GET Request
    const getRes = await client.get('https://httpbin.org/get');
    console.log('Status:', getRes.statusCode);
    console.log('Response JSON:', getRes.json());

    // POST Request
    const postRes = await client.post('https://httpbin.org/post', {
      user: 'alice',
      action: 'login'
    }, {
      'Authorization': 'Bearer secret-token'
    });
    console.log('Echoed Data:', postRes.json().json);

  } catch (error) {
    console.error('Proxy Client Error:', error.message);
  }
}

run();

📖 API Reference

MtlsProxyServer

new MtlsProxyServer(options)

  • options.key (string | Buffer): Path or Buffer containing server.key. Required.
  • options.cert (string | Buffer): Path or Buffer containing server.crt. Required.
  • options.ca (string | Buffer): Path or Buffer containing ca.crt. Required.
  • options.port (number): Port number to listen on. Default: 13159.
  • options.host (string): Host/IP interface to bind to. Default: '0.0.0.0'.

Methods

  • server.listen(): Starts the HTTPS server. Returns Promise<https.Server>.
  • server.close(): Stops the HTTPS server. Returns Promise<void>.

MtlsProxyClient

new MtlsProxyClient(options)

  • options.proxyHost (string): Proxy server host/IP address. Required.
  • options.key (string | Buffer): Path or Buffer containing client.key. Required.
  • options.cert (string | Buffer): Path or Buffer containing client.crt. Required.
  • options.ca (string | Buffer): Path or Buffer containing ca.crt. Required.
  • options.proxyPort (number): Proxy port. Default: 13159.
  • options.rejectUnauthorized (boolean): Verify proxy TLS cert. Default: true.

Methods

All request methods return a Promise resolving to a Response Object:

{
  statusCode: number;           // HTTP response status code (e.g. 200)
  headers: IncomingHttpHeaders; // Response headers object
  data: string;                 // Raw response body as text
  buffer: Buffer;               // Raw response body as Buffer
  json: () => T;                // Helper function to parse data as JSON
}
.get(targetUrl, [headers], [options])
.post(targetUrl, [data], [headers], [options])
.put(targetUrl, [data], [headers], [options])
.patch(targetUrl, [data], [headers], [options])
.delete(targetUrl, [headers], [options])
.request(targetUrl, options)
  • targetUrl (string): Full URL of destination server (e.g. 'https://api.example.com/v1/data').
  • options.method (string): HTTP method verb. Default: 'GET'.
  • options.data (any): Request body payload (Object, string, or Buffer).
  • options.headers (Object): Object containing custom HTTP request headers.
  • options.timeout (number): Request timeout in milliseconds.

📄 License

MIT