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

multibucket

v1.0.2

Published

A library to generate presigned URLs for multiple storage providers (AWS S3, Cloudflare R2) with load balancing

Readme

Multi-Storage Presigner

A Node.js library for generating presigned URLs for multiple object storage providers (AWS S3, Cloudflare R2) with automatic load balancing.

Features

  • Support for multiple storage providers (AWS S3 and Cloudflare R2)
  • Automatic load balancing between providers using various strategies
  • Live configuration updates from file or remote URL
  • Rate limiting and error handling
  • RESTful API endpoints for generating presigned URLs
  • Monitoring and statistics

Installation

npm install multibucket

TypeScript

This package includes a minimal index.d.ts so TypeScript projects can import it with type information. Example:

import MultiBucket = require('multibucket');
// or (with `esModuleInterop` enabled in tsconfig):
// import MultiBucket from 'multibucket';

const mb = new MultiBucket({ providers: [] });

If your TypeScript project still complains about missing types, you can either enable esModuleInterop in tsconfig.json, or, as a temporary workaround, add a declaration stub in the consuming project like declare module 'multibucket';.

Dependencies

This library requires the following dependencies:

npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner express axios chokidar

Basic Usage

const MultiBucket = require('multibucket');

// Create an instance with initial providers
const storagePresigner = new MultiBucket({
  providers: [
    {
      id: 's3-main',
      type: 's3',
      bucket: 'my-main-bucket',
      region: 'us-east-1',
      accessKeyId: 'YOUR_AWS_ACCESS_KEY',
      secretAccessKey: 'YOUR_AWS_SECRET_KEY',
      weight: 3,
      rateLimit: 100
    },
    {
      id: 'r2-cloudflare',
      type: 'r2',
      bucket: 'my-r2-bucket',
      endpoint: 'https://account-id.r2.cloudflarestorage.com',
      accessKeyId: 'YOUR_R2_ACCESS_KEY',
      secretAccessKey: 'YOUR_R2_SECRET_KEY',
      publicUrlBase: 'https://cdn.example.com'
    }
  ],
  loadBalanceStrategy: 'round-robin',
  defaultExpiry: 3600
});

// Start the API server
storagePresigner.createServer(3000);

Configuration Options

Constructor Options

  • providers: Array of storage provider configurations
  • configSource: Path or URL to a config file (optional)
  • loadBalanceStrategy: Strategy for load balancing (default: 'round-robin')
  • defaultExpiry: Default expiry time for presigned URLs in seconds (default: 3600)

Provider Configuration

Each provider object requires the following properties:

Common Properties:

  • id: Unique identifier for the provider
  • type: Provider type ('s3' or 'r2')
  • bucket: Bucket name
  • accessKeyId: Access key ID
  • secretAccessKey: Secret access key
  • weight (optional): Weight for weighted-random load balancing
  • rateLimit (optional): Maximum requests per second
  • publicUrlBase (optional): Base URL for public access

S3-specific Properties:

  • region: AWS region
  • endpoint (optional): Custom endpoint for S3-compatible services
  • forcePathStyle (optional): Use path-style addressing

R2-specific Properties:

  • endpoint: R2 endpoint URL

Load Balancing Strategies

  • round-robin: Cycle through providers sequentially
  • least-used: Select the provider with the fewest requests
  • least-errors: Select the provider with the lowest error rate
  • weighted-random: Select providers randomly based on their weight

External Configuration

You can provide a path to a JSON file or a URL in the configSource option:

const storagePresigner = new MultiBucket({
  configSource: './storage-config.json'
});

The library will watch for changes to the file or poll the URL to update the configuration dynamically.

API Endpoints

When you start the server with createServer(), the following endpoints are available:

Generate Upload URL

POST /generate-upload-url

Request body:

{
  "filename": "example.jpg",
  "contentType": "image/jpeg",
  "path": "uploads/images",
  "expiry": 1800,
  "providerId": "s3-main"
}

Response:

{
  "uploadUrl": "https://my-main-bucket.s3.us-east-1.amazonaws.com/uploads/images/uuid-example.jpg?...",
  "publicUrl": "https://my-main-bucket.s3.us-east-1.amazonaws.com/uploads/images/uuid-example.jpg",
  "key": "uploads/images/uuid-example.jpg",
  "bucket": "my-main-bucket",
  "provider": "s3-main",
  "expires": "2023-06-01T12:30:00.000Z"
}

Generate Read URL

POST /generate-read-url

Request body:

{
  "key": "uploads/images/uuid-example.jpg",
  "providerId": "s3-main",
  "expiry": 3600
}

Response:

{
  "readUrl": "https://my-main-bucket.s3.us-east-1.amazonaws.com/uploads/images/uuid-example.jpg?...",
  "key": "uploads/images/uuid-example.jpg",
  "bucket": "my-main-bucket",
  "provider": "s3-main",
  "expires": "2023-06-01T13:00:00.000Z"
}

Get Stats

GET /stats

Response:

{
  "providerCount": 2,
  "totalRequests": 150,
  "providerStats": [
    {
      "id": "s3-main",
      "type": "s3",
      "requestCount": 100,
      "errorCount": 2,
      "errorRate": "0.0200"
    },
    {
      "id": "r2-cloudflare",
      "type": "r2",
      "requestCount": 50,
      "errorCount": 0,
      "errorRate": "0.0000"
    }
  ]
}

Health Check

GET /health

Response:

{
  "status": "ok",
  "providers": 2,
  "timestamp": "2023-06-01T11:00:00.000Z"
}

Programmatic Usage

You can also generate presigned URLs programmatically:

// Generate upload URL
const uploadUrlInfo = await storagePresigner.generateUploadUrl({
  filename: 'example.jpg',
  contentType: 'image/jpeg',
  path: 'uploads/images',
  expiry: 1800
});

// Generate read URL
const readUrlInfo = await storagePresigner.generateReadUrl({
  key: 'uploads/images/uuid-example.jpg',
  providerId: 's3-main',
  expiry: 3600
});