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-temp

v0.1.0

Published

Upload files to S3 with automatic cleanup

Readme

s3-temp

Upload files to S3 with automatic cleanup. Useful in tests and scripts that need to stage a file in S3 temporarily and remove it when done.

How it works

Each function uploads a file to S3 and returns a TempFileOnS3 object containing the resolved key, the ETag from S3, and an async cleanup() function that deletes the object when called.

If no key is provided, one is generated automatically: for file uploads the original filename is preserved with a UUID suffix (e.g. report_3a9f...c1.pdf), and for string uploads a plain UUID is used with an optional extension.

Installation

npm install s3-temp

Usage

Upload a local file

import { tempFileOnS3 } from 's3-temp'

const { cleanup, key, eTag } = await tempFileOnS3({
  localPath: '/tmp/report.pdf',
  bucket: 'my-bucket',
})
try {
  // Work with `key` and optionally `eTag`.
} finally {
  await cleanup()
}

Provide a key to use a fixed path instead of a generated one:

const key = 'uploads/report.pdf'
const { cleanup, eTag } = await tempFileOnS3({
  localPath: '/tmp/report.pdf',
  bucket: 'my-bucket',
  key,
})
try {
  // Work with `key` and optionally `eTag`.
} finally {
  await cleanup()
}

Upload a string

import { tempFileOnS3FromString } from 's3-temp'

const { cleanup, key, eTag } = await tempFileOnS3FromString({
  contents: '<html>hello</html>',
  bucket: 'my-bucket',
  extension: '.html',
})
try {
  // Work with `key` and optionally eTag.
} finally {
  await cleanup()
}

API

tempFileOnS3(options): Promise<TempFileOnS3>

| Option | Type | Required | Description | | ----------- | ---------------- | -------- | ----------------------------------------- | | localPath | string | yes | Path to the local file to upload | | bucket | string | yes | S3 bucket name | | key | string | no | S3 object key (auto-generated if omitted) | | encoding | BufferEncoding | no | File encoding passed to fs.readFile | | verbose | boolean | no | Log upload/removal to stderr |

tempFileOnS3FromString(options): Promise<TempFileOnS3>

| Option | Type | Required | Description | | ----------- | --------- | -------- | ---------------------------------------------------- | | contents | string | yes | String content to upload | | bucket | string | yes | S3 bucket name | | key | string | no | S3 object key (auto-generated if omitted) | | extension | string | no | Extension appended to generated key (e.g. '.json') | | verbose | boolean | no | Log upload/removal to stderr |

TempFileOnS3

| Property | Type | Description | | ----------- | --------------------- | ----------------------------- | | key | string | The S3 object key | | eTag | string | ETag returned by S3 on upload | | cleanup() | () => Promise<void> | Deletes the object from S3 |

Development

Environment variables

The integration tests upload real objects to S3. Copy .env.example to .env and fill in the values before running tests.

| Variable | Description | | ------------- | ---------------------------------------------------- | | AWS_PROFILE | AWS credentials profile to use for local development | | AWS_REGION | AWS region (e.g. us-east-1) | | TEST_BUCKET | S3 bucket to use for integration tests |

For local development, set AWS_PROFILE and AWS_REGION to use a credentials profile from ~/.aws/credentials. In CI, omit these and set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY directly.

Running tests

npm test