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

tor-js

v0.3.2

Published

TypeScript Tor client using arti via WASM

Downloads

400

Readme

tor-js

Make HTTP requests through Tor from JavaScript. Works in browsers and Node.js.

Uses Arti (the Tor Project's Rust implementation) compiled to WebAssembly.

Live Demo

Status

Experimental.

It is your responsibilty to decide whether tor-js meets your security requirements. This software is provided for free and without warranty, per the MIT license.

Please reach out (on github or otherwise) if you'd like to see more security validation for tor-js.

Quick start

npm install tor-js
import { TorClient } from 'tor-js';

const client = new TorClient({
  // gateway: 'https://tor-js-gateway.HOSTME.com',

  // (In NodeJS you can leave this commented, but browsers
  // don't have raw TCP and so require help to connect to
  // the tor network.
  // https://github.com/privacy-ethereum/tor-js-gateway)
});

const response = await client.fetch('https://check.torproject.org/api/ip');
console.log(await response.json()); // { IsTor: true, IP: "..." }

client.close();

Entry points

The package offers three ways to load the WASM binary. All export the same API.

| Import | WASM loading | Size (gzip) | Best for | |---|---|---|---| | tor-js | Fetched from CDN, cached locally | 17 kB | Production web apps | | tor-js/wasm-base64 | Embedded in the JS bundle | 2.3 MB | Single-file deploys | | tor-js/wasm-file | Loaded from tor_js_bg.wasm next to the module | 15 kB + 1.7 MB | Self-hosted, server-side |

Each also has a /singleton variant (see Singleton below).

API

new TorClient(options)

Creates a Tor client and begins bootstrapping immediately.

type TorClientOptions = {
  gateway?: string;       // Gateway URL (required in browsers, optional in Node.js/Deno)
  log?: Log;              // Logger instance (default: silent)
  storage?: TorStorage;   // Persistent storage (default: auto-detected)
  logLevel?: LogLevel;    // 'trace' | 'debug' | 'info' | 'warn' | 'error'
};

In browsers, the gateway proxies relay connections via WebRTC or WebSocket. In Node.js/Deno, connections go via direct TCP and the gateway is only used for fast bootstrap (optional).

client.fetch(url, init?)

Make an HTTP request through Tor. Returns a standard Response object.

Waits for the client to be fully ready before sending the request.

const res = await client.fetch('https://example.com', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ key: 'value' }),
  signal: AbortSignal.timeout(30_000),
});

client.ready()

Wait for the client to be ready for traffic (guard connected, usable consensus, sufficient microdescs). Called automatically by fetch(), but useful to call early if you want to measure bootstrap time or show a loading state.

const client = new TorClient({ ... });
await client.ready();
console.log('Bootstrap complete');

client.setLogLevel(level)

Change the log level at runtime. Accepts 'trace', 'debug', 'info', 'warn', or 'error'.

client.close()

Close the client and release resources. Also available as Symbol.dispose for use with using:

{
  using client = new TorClient({ ... });
  await client.fetch('https://example.com');
} // automatically closed

Singleton

For simple use cases, import the singleton wrapper:

import { tor } from 'tor-js/singleton';

// tor.configure({
//   gateway: 'https://tor-js-gateway.HOSTME.com',
//
//   (In NodeJS you can leave this commented, but browsers
//   don't have raw TCP and so require help to connect to
//   the tor network.
//   https://github.com/privacy-ethereum/tor-js-gateway)
// });

const response = await tor.fetch('https://check.torproject.org/api/ip');

The singleton auto-opens on first fetch(). Use tor.configure(options) to change settings, or tor.close() to shut down.

Storage

By default, TorClient auto-detects the best storage for the environment:

  • Browser: IndexedDB
  • Node.js: ~/.local/share/tor-js/

Cached consensus and microdescriptors are persisted, so subsequent connections bootstrap faster.

You can provide your own storage:

import { TorClient, storage } from 'tor-js';

// Explicit IndexedDB
const client = new TorClient({
  storage: new storage.IndexedDBStorage('my-app'),
  // ...
});

// In-memory (no persistence)
const client = new TorClient({
  storage: new storage.MemoryStorage(),
  // ...
});

Logging

Pass a Log instance to see bootstrap progress and debug info:

import { TorClient, Log } from 'tor-js';

const client = new TorClient({
  log: new Log(),       // logs to console with timestamps
  logLevel: 'info',     // minimum level (default: 'debug')
  // ...
});

Custom log sink:

const log = new Log({
  rawLog: (level, ...args) => myLogger[level](...args),
});

License

MIT OR Apache-2.0