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

s3-adaptor

v0.2.0

Published

Adapter-pattern interface for AWS S3 and local filesystem storage, with signed URLs and Express middleware

Downloads

174

Readme

s3-adaptor

Unified adapter-pattern interface for AWS S3 and local filesystem storage. Switch backends via config — same API in dev and production. Includes signed URL generation and Express middleware for local dev serving.

Install

pnpm add s3-adaptor
# peer dep for middleware:
pnpm add express

Quick Start

Local (dev)

import { S3Adaptor } from 's3-adaptor'

const storage = new S3Adaptor({
  defaultType: 'local',
  local: {
    storagePath: '/tmp/storage',
    baseUrl: 'http://localhost:3000/files',
    secretKey: 'supersecretkey-atleast-32-chars!',
    buckets: {
      avatars: { public: true },  // no token required to read
      docs:    { public: false }, // token required (default)
    },
  },
})

S3 (production)

const storage = new S3Adaptor({
  defaultType: 's3',
  s3: { region: 'us-east-1' }, // uses AWS SDK default credential chain
})

API

// Upload
await storage.putObject({ Bucket, Key, Body, ContentType?, Metadata? })

// Download — returns { Body: ReadableStream, ContentType?, ContentLength?, ETag?, Metadata? }
const result = await storage.getObject({ Bucket, Key })

// Delete
await storage.deleteObject({ Bucket, Key })

// List — returns { Contents: [{ Key, Size, LastModified, ETag? }], IsTruncated }
const list = await storage.listObjects({ Bucket, Prefix?, MaxKeys? })

// Signed URL — public bucket → plain URL; protected → ?token=<signed> (local); S3 → pre-signed
const url = await storage.getSignedUrl({ Bucket, Key, Expires? })

Express Middleware (local only)

import { createLocalFileMiddleware } from 's3-adaptor'

// Mount as: GET /files/:bucket/*key (Express 5) or /files/:bucket/* (Express 4)
app.get('/files/:bucket/*key', createLocalFileMiddleware(config.local))

Access control is based on bucket policy:

  • Public bucket: serves file without token
  • Protected bucket: requires ?token=<signed> obtained from getSignedUrl

Bucket Access Modes

| Mode | BucketPolicy.public | getSignedUrl result | Middleware | |-----------|-----------------------|-------------------------|-----------------------| | Public | true | plain URL, no token | serves without token | | Protected | false (default) | URL with ?token=<...> | requires valid token |

Error Classes

All errors extend S3AdaptorError with a code property.

| Class | code | When | |----------------------|------------------|-------------------------------| | NotFoundError | NOT_FOUND | Object missing | | AccessDeniedError | ACCESS_DENIED | No token on protected bucket | | InvalidTokenError | INVALID_TOKEN | Tampered or wrong-scope token | | TokenExpiredError | TOKEN_EXPIRED | Token past expiry | | InvalidConfigError | INVALID_CONFIG | Bad constructor config |

Scripts

pnpm build    # tsc → dist/
pnpm test     # jest
pnpm format   # prettier --write ./src
pnpm lint     # eslint src