pipenet

1.4.0 · active · verified Sun Apr 19

pipenet is a Node.js library and CLI tool designed to instantly expose local development servers to the public internet, facilitating testing and collaboration without complex network configurations. Currently at version 1.4.0, the project demonstrates an active release cadence with several updates in early 2026, including features like adding hooks and shared tunnel server capabilities for cloud deployments. It offers both a command-line interface for quick usage and a programmatic API for deeper integration into automated workflows or testing environments. Key differentiators include the ability to request specific subdomains, support for custom upstream tunnel servers, and the option to run a self-hosted pipenet server with custom domains and multiple domain support, providing flexibility for various deployment scenarios. It ships with TypeScript types, promoting better developer experience in typed environments.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to programmatically create a pipenet tunnel, exposing a basic local HTTP server to the public internet. It illustrates awaiting the tunnel URL, logging incoming requests, and handling potential errors or the tunnel's closure, providing a complete, runnable setup for integrating `pipenet` into a Node.js application.

import { pipenet } from 'pipenet';
import http from 'http';
import { AddressInfo } from 'net'; // For checking server address

async function startPipenetTunnel() {
  // Create a simple local HTTP server to expose
  const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end(`Hello from pipenet! Requested path: ${req.url}\n`);
  });

  const localPort = 3000;
  server.listen(localPort, () => {
    const address = server.address() as AddressInfo;
    console.log(`Local HTTP server listening on ${address.address}:${address.port}`);
  });

  try {
    // Create a pipenet tunnel to expose the local server
    const tunnel = await pipenet({
      port: localPort,
      // host: 'https://pipenet.dev', // Defaults to pipenet.dev if not specified
      subdomain: `my-test-app-${Math.random().toString(36).substring(2, 7)}` // Request a dynamic subdomain
    });

    console.log(`PTP Tunnel established! Public URL: ${tunnel.url}`);

    tunnel.on('request', (info) => {
      console.log(`[Tunnel Event] Request processed: ${info.method} ${info.path}`);
    });

    tunnel.on('error', (err) => {
      console.error('[Tunnel Event] An error occurred:', err.message);
    });

    tunnel.on('close', () => {
      console.log('[Tunnel Event] Tunnel has closed. Shutting down local server...');
      server.close(() => console.log('Local server closed.'));
    });

    // Automatically close the tunnel after a period (e.g., 60 seconds) for demonstration
    setTimeout(() => {
      console.log('Automatically closing tunnel after 60 seconds...');
      tunnel.close();
    }, 60000);

  } catch (error: any) {
    console.error('Failed to create pipenet tunnel:', error.message);
    server.close();
  }
}

startPipenetTunnel();

view raw JSON →