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

@farm.js/tunnel

v0.1.1

Published

Persistent Rust N-API preview tunnel for Farm.js

Readme

@farm.js/tunnel

Experimental implementation of Farm's persistent preview tunnel protocol.

The agent opens one outbound WebSocket to a Farm preview relay, receives multiplexed HTTP requests, forwards them to a local app, and returns responses over the same connection. It is intentionally stored outside the Farm.js monorepo so it can be released as an optional native package.

Build

npm install
npm run build

Node API

const {
  startPreviewAgent,
  stopPreviewAgent,
  waitPreviewAgent,
} = require("@farm.js/tunnel");

const session = await startPreviewAgent(
  "ws://127.0.0.1:4400/agent",
  "my-preview",
  "http://127.0.0.1:3000",
);

console.log(session.publicUrl);
await waitPreviewAgent(session.sessionId);

Call stopPreviewAgent(session.sessionId) during explicit shutdown. waitPreviewAgent(session.sessionId) resolves when either the relay or local target closes the session, allowing a CLI process to share the tunnel lifecycle.

The agent buffers response bodies only up to the limit advertised by the relay (5 MiB by default). It drops the upstream body immediately and returns a 502 response if the local app exceeds that limit.

When the relay reports that a public visitor disconnected or a request timed out, the agent aborts only the matching localhost request. Other concurrent preview traffic continues normally.

Why N-API instead of WASM?

The agent owns native TCP/TLS/WebSocket connections and forwards arbitrary HTTP bodies. N-API allows the Rust runtime to do that work directly while presenting a small JavaScript API. A WASM build would still need JavaScript host shims for networking and would not provide a useful comparison of the native transport.

Initial benchmark

On an Apple M1 with a 4 KiB payload and the same loopback relay/protocol, the optimized Rust agent averaged 0.29 ms sequentially and 4.45 ms at concurrency 25. The TypeScript agent averaged 0.47 ms and 7.34 ms respectively. Rust delivered about 61–65% more throughput in this agent-overhead benchmark.

The benchmark harness and full methodology live in the sibling Farm.js repository under benchmarks/preview-tunnel. These numbers isolate agent overhead; a production relay benchmark must also include TLS and real network distance.