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

@tyvm/knowhow-tunnel

v0.0.3

Published

HTTP tunnel implementation for knowhow worker

Readme

Knowhow Tunnel

HTTP tunnel implementation for proxying requests from a remote server to localhost services.

Features

  • HTTP/HTTPS Proxying: Stream HTTP requests to local services
  • WebSocket Support: Proxy WebSocket connections (e.g., for HMR)
  • Streaming: Zero-copy streaming with proper backpressure handling
  • Security: Port allowlisting, concurrency limits, size limits
  • Observability: Structured logging and metrics

Installation

npm install @tyvm/knowhow-tunnel

Usage

Basic Example

import WebSocket from "ws";
import { createTunnelHandler } from "@tyvm/knowhow-tunnel";

// Create WebSocket connection to server
const ws = new WebSocket("ws://server.com/tunnel");

// Create tunnel handler
const tunnel = createTunnelHandler(ws, {
  allowedPorts: [3000, 8080],
  maxConcurrentStreams: 50,
  logLevel: "info",
});

// Get stats
console.log(tunnel.getStats());

Docker / Sandbox Mode

When running in Docker, use host.docker.internal to access host services:

const tunnel = createTunnelHandler(ws, {
  allowedPorts: [3000],
  localHost: "host.docker.internal",
  logLevel: "info",
});

Or use port mapping if services run on different ports:

const tunnel = createTunnelHandler(ws, {
  allowedPorts: [3000],
  portMapping: { 3000: 8080 }, // Remote 3000 -> Local 8080
  logLevel: "info",
});

Configuration

interface TunnelConfig {
  // Allowed ports for tunneling (empty = none allowed, safe default)
  allowedPorts?: number[];
  
  // Maximum concurrent streams
  maxConcurrentStreams?: number;
  
  // Maximum response size per stream (bytes)
  maxResponseSize?: number;
  
  // Connection timeout (ms)
  connectTimeout?: number;
  
  // Idle timeout (ms)
  idleTimeout?: number;
  
  // Force identity encoding (no compression)
  forceIdentityEncoding?: boolean;
  
  // Local host to proxy to
  localHost?: string;
  
  // Port mapping (remote port -> local port)
  // Useful for Docker or when services run on different ports
  portMapping?: {
    [remotePort: number]: number;
  };
  
  // Log level
  logLevel?: "debug" | "info" | "warn" | "error";
}

Protocol

The tunnel uses JSON messages over WebSocket for control flow and streaming.

Request Flow

  1. TUNNEL_REQUEST: Server sends request metadata

    {
      "type": "TUNNEL_REQUEST",
      "streamId": "uuid",
      "port": 3000,
      "method": "GET",
      "path": "/api/users",
      "headers": { ... },
      "scheme": "http"
    }
  2. TUNNEL_DATA: Request body chunks (if any)

    {
      "type": "TUNNEL_DATA",
      "streamId": "uuid",
      "data": "<base64>"
    }
  3. TUNNEL_END: End of request body

    {
      "type": "TUNNEL_END",
      "streamId": "uuid"
    }

Response Flow

  1. TUNNEL_RESPONSE: Agent sends response metadata

    {
      "type": "TUNNEL_RESPONSE",
      "streamId": "uuid",
      "statusCode": 200,
      "headers": { ... }
    }
  2. TUNNEL_DATA: Response body chunks

  3. TUNNEL_END: End of response

Error Handling

{
  "type": "TUNNEL_ERROR",
  "streamId": "uuid",
  "error": "Connection refused",
  "statusCode": 502
}

WebSocket Upgrade

For WebSocket connections (e.g., HMR):

{
  "type": "TUNNEL_WS_UPGRADE",
  "streamId": "uuid",
  "port": 3000,
  "path": "/_next/webpack-hmr",
  "headers": { ... }
}

Integration with Worker

See src/worker.ts for integration example.

Architecture

Server (Remote)          WebSocket          Agent (Local)
     |                      |                      |
     |-- TUNNEL_REQUEST --->|                      |
     |                      |--- handleRequest --->| http.request()
     |                      |                      |    to localhost:port
     |<-- TUNNEL_RESPONSE --|                      |
     |<-- TUNNEL_DATA -------|<-- stream response -|
     |<-- TUNNEL_END --------|                     |

Security Considerations

  • Only tunnels to 127.0.0.1 by default
  • Port allowlisting prevents unauthorized access
  • Concurrency limits prevent resource exhaustion
  • Size limits prevent memory issues
  • Idle timeouts cleanup stale connections

License

MIT