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

snap-bucket-server

v1.0.1

Published

### Express middleware to generate secure, short-lived AWS S3 pre-signed upload URLs.

Readme

📦 snap-bucket-server

Express middleware to generate secure, short-lived AWS S3 pre-signed upload URLs.

npm version License

snap-bucket-server is the backend companion SDK of the Snap Bucket ecosystem. It creates an Express-compatible router to dynamically validate and issue single-use S3 pre-signed upload URLs directly in response to metadata requests sent by the snap-bucket frontend library.


🚀 Features

  • Secure by Design: Your AWS credentials remain sealed in your backend server.
  • Plug-and-play Express Router: Mounts in a single line.
  • Automatic Namespace Prefixing: Integrated timestamping to avoid S3 file overwrites.
  • Pre-signed Expiration: Issues highly restrictive 60-second execution windows.
  • Fully Typed: Full TypeScript interfaces out-of-the-box.

📦 Installation

Install the package and required peer dependencies (e.g. express):

npm install snap-bucket-server
# or
yarn add snap-bucket-server
# or
pnpm add snap-bucket-server

⚡ Quick Start

1. Configure S3 Environment Variables

Ensure your system uses appropriate S3 configuration flags. Create a .env file:

AWS_REGION=us-east-1
AWS_BUCKET=your-target-bucket-name
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

2. Mount createUploadRouter()

Set up your Express application and register the upload router:

import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import { createUploadRouter } from "snap-bucket-server";

dotenv.config();

const app = express();

// Enable CORS for frontend applications
app.use(cors({
  origin: "http://localhost:5173", // URL of your frontend server
  credentials: true
}));

// CRITICAL: Mount JSON parser middleware BEFORE the router
app.use(express.json());

// Register the Upload endpoint
app.use(
  "/api/upload",
  createUploadRouter({
    bucket: process.env.AWS_BUCKET!,
    region: process.env.AWS_REGION!,
    accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!
  })
);

app.listen(3000, () => {
  console.log("S3 Token server listening on port 3000");
});

📖 API Reference

createUploadRouter()

Generates an Express Router targeting your bucket parameters.

function createUploadRouter(config: ConnectifyConfig): express.Router;

Configuration Options:

  • bucket (string): Target Amazon S3 bucket name.
  • region (string): Bucket region (e.g. us-east-2).
  • accessKeyId (string): IAM User credentials containing S3 write clearance.
  • secretAccessKey (string): IAM User Secret Key.

Route Details:

  • Method: POST
  • Path: / (mount endpoint, e.g., /api/upload)
  • Payload Requirements (JSON):
    {
      "fileName": "avatar.jpg",
      "contentType": "image/jpeg",
      "folder": "users/profiles"
    }
  • Return Format:
    {
      "uploadUrl": "https://[bucket].s3.[region].amazonaws.com/[folder]/[timestamp]-avatar.jpg?AWSAccessKeyId=...",
      "fileUrl": "https://[bucket].s3.[region].amazonaws.com/[folder]/[timestamp]-avatar.jpg"
    }

🛡️ S3 Bucket CORS Settings

Direct browser PUT streams are blocked by S3 default policies. Add this CORS config to your S3 bucket permissions dashboard:

[
  {
    "AllowedHeaders": ["*"],
    "AllowedMethods": ["PUT", "POST", "GET"],
    "AllowedOrigins": ["http://localhost:5173"],
    "ExposeHeaders": ["ETag"],
    "MaxAgeSeconds": 3000
  }
]

📄 License

License