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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rabbito

v1.0.0

Published

Finds the fastest download speed from a set of urls.

Readme

🐰 Rabbito

wakatime Node.js CI GitHub License GitHub Release codecov 0 Dependencies Size typescript Types npm npm GitHub issues GitHub stars Node & Bun Maintenance npm version License: MIT

A tiny, high-performance library to find the fastest download URL from a set of URLs. Rabbito automatically tests download speeds from multiple sources and returns the best option.

Features

  • 🚀 Fast & Lightweight: Minimal dependencies and optimized for performance
  • Race-based Testing: Tests multiple URLs concurrently and returns the fastest
  • 🔄 Smart Abortion: Automatically cancels slower downloads once a faster one is found
  • 🔌 Environment Agnostic: Works in both Node.js and Bun runtimes

Installation

# Using npm
npm install rabbito

# Using yarn
yarn add rabbito

# Using pnpm
pnpm add rabbito

# Using bun
bun add rabbito

Usage

Finding the Fastest Download URL

import { findBestDownloadUrl } from 'rabbito';

async function downloadFromFastestMirror() {
    const mirrors = [
        'https://mirror1.example.com/file.zip',
        'https://mirror2.example.com/file.zip',
        'https://mirror3.example.com/file.zip',
    ];

    try {
        // Find the fastest URL
        const fastestUrl = await findBestDownloadUrl(mirrors, {
            onUrlFailure: (url, error) => {
                console.error(`Failed to test ${url}:`, error);
            },
            sampleBytes: 128000, // Use smaller sample (128KB)
            timeoutMs: 10000, // 10 second timeout
            onProgress: (info) => {
                console.log(
                    `${info.url}: ${Math.round((info.bytesDownloaded / info.totalBytes) * 100)}% - ${Math.round(info.currentSpeed / 1024)} KB/s`,
                );
            },
        });

        console.log(`Fastest mirror found: ${fastestUrl}`);

        // Now you can use the fastest URL for your actual download
        const response = await fetch(fastestUrl);
        // Process the download...
    } catch (error) {
        console.error('All mirrors failed:', error);
    }
}

downloadFromFastestMirror();

Checking URL Health

import { checkUrlsHealth } from 'rabbito';

async function checkMirrors() {
    const mirrors = [
        'https://mirror1.example.com/file.zip',
        'https://mirror2.example.com/file.zip',
        'https://mirror3.example.com/file.zip',
    ];

    try {
        // Check if URLs are accessible
        const results = await checkUrlsHealth(mirrors, {
            timeoutMs: 5000, // 5 second timeout
            httpsOnly: true, // Only allow HTTPS URLs
        });

        // Filter healthy mirrors
        const healthyMirrors = results.filter((result) => result.healthy).map((result) => result.url);

        console.log(`Found ${healthyMirrors.length} healthy mirrors`);

        // Log errors for unhealthy mirrors
        const unhealthyMirrors = results.filter((result) => !result.healthy);
        if (unhealthyMirrors.length > 0) {
            console.log('Unhealthy mirrors:');
            unhealthyMirrors.forEach((result) => {
                console.log(`- ${result.url}: ${result.error}`);
            });
        }

        return healthyMirrors;
    } catch (error) {
        console.error('Failed to check mirrors:', error);
        return [];
    }
}

checkMirrors();

API

findBestDownloadUrl(urls: string[], options?: FindBestDownloadUrlOptions): Promise<string>

Tests the download speed of multiple URLs and returns the fastest one.

Parameters:

  • urls: An array of URLs to test
  • options: (Optional) Configuration options
    • onUrlFailure: Callback function that is invoked when a URL fails the speed test
    • sampleBytes: Size of data to download for testing (default: 256KB)
    • timeoutMs: Timeout for each URL test in milliseconds (default: 30000)
    • maxConcurrent: Maximum number of URLs to test concurrently
    • earlyTerminationThreshold: Threshold to stop testing if a clearly faster URL is found
    • retries: Number of times to retry failed URLs (default: 0)
    • retryDelayMs: Delay between retries in milliseconds (default: 1000)
    • httpsOnly: Whether to only allow HTTPS URLs (default: false)
    • onProgress: Callback for progress updates during download tests

Returns:

  • A Promise that resolves to the URL string with the fastest download speed.

Throws:

  • Error if all URLs fail the speed test

checkUrlsHealth(urls: string[], options?): Promise<Array<{url: string; healthy: boolean; error?: string}>>

Checks if URLs are accessible without performing a full speed test.

Parameters:

  • urls: An array of URLs to check
  • options: (Optional) Configuration options
    • timeoutMs: Timeout for each URL check in milliseconds
    • httpsOnly: Whether to only allow HTTPS URLs (default: false)

Returns:

  • A Promise that resolves to an array of objects containing:
    • url: The URL that was checked
    • healthy: Boolean indicating if the URL is accessible
    • error: Error message if the URL is not healthy (undefined otherwise)

How It Works

Rabbito works by:

  1. Initiating parallel fetch requests to all provided URLs
  2. Downloading a small sample (~256KB) from each URL
  3. Measuring the download speed for each URL
  4. Canceling slower downloads once a faster one completes
  5. Returning the URL with the best performance

This approach minimizes bandwidth usage while efficiently finding the optimal download source.

Requirements

  • Node.js >= 22.0.0 or Bun >= 1.2.11

License

MIT © Ragaeeb Haq