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

@reupload/client

v0.2.0

Published

Browser client for Reupload uploads via your backend file router

Readme

@reupload/client

Browser client for uploading files through your backend file router — never expose a Reupload API key in the front end.

Works in React, Next.js (App + Pages), SolidStart, Vite, and any environment with fetch and FormData.

Pair with @reupload/sdk on your server, or any API that implements the default routes below.

Install

npm install @reupload/client

Optional React hook:

npm install @reupload/client react

Environment

# Next.js
NEXT_PUBLIC_API_URL=http://localhost:3001

# Vite
VITE_API_URL=http://localhost:3001

Quick start (CDN flow)

Your backend exposes POST /uploads/prepare, the browser PUTs to the signed CDN URL, then POST /uploads/complete. See the React/Next + Node guide.

import { createReuploadClientFromEnv } from "@reupload/client";

const client = createReuploadClientFromEnv();

async function onFileSelected(file: File) {
  const { uploadId, fileId } = await client.uploadFile(file);

  const final = await client.pollUploadStatus(uploadId);
  if (final.status === "COMPLETED") {
    console.log("Ready:", fileId);
  }
}

Backend file router

Default paths (override with routes in the constructor):

| Method | Path | Purpose | |--------|------|---------| | POST | /uploads/prepare | Create session → return uploadUrl, uploadId, fileId | | POST | /uploads/complete | Finalize CDN upload ({ uploadId }) | | GET | /uploads/:uploadId/status | Poll { status, fileId } | | GET | /files/:fileId/access | Signed download URL |

Custom paths:

const client = new ReuploadClient({
  apiUrl: "https://api.myapp.com",
  routes: {
    prepare: "/api/v1/files/prepare",
    status: (id) => `/api/v1/files/uploads/${id}`,
  },
});

Use @reupload/sdk on your server to implement these routes.

API

ReuploadClient

| Method | Description | |--------|-------------| | uploadFile(file, options?) | Full CDN flow via your backend | | prepareUpload(meta) | Step 1 only (CDN) | | completeUpload({ uploadId }) | Step 3 only (CDN) | | getUploadStatus(uploadId) | Single status poll | | pollUploadStatus(uploadId, options?) | Poll until terminal status | | getFileAccess(fileId, query?) | Signed URL from your backend | | openFileInNewTab(fileId) | window.open(access.url) |

Low-level

  • putFileToUploadUrl(uploadUrl, file, { onProgress }) — CDN PUT with optional XMLHttpRequest progress
  • validateFile(file, { maxBytes, accept }) — client-side checks before upload
  • pollUploadStatus(fetcher, options) — standalone poller

Errors

import { isReuploadClientError } from "@reupload/client";

try {
  await client.uploadFile(file);
} catch (error) {
  if (isReuploadClientError(error)) {
    console.log(error.phase); // "backend" | "cdn"
    console.log(error.status, error.message);
  }
}

React hook

"use client";

import { useReuploadUpload } from "@reupload/client/react";

export function FileUpload() {
  const { upload, state, reset, isUploading } = useReuploadUpload({
    validation: { maxBytes: 52_428_800, accept: ["image/*", "application/pdf"] },
  });

  return (
    <div>
      <input
        type="file"
        disabled={isUploading}
        onChange={(e) => {
          const file = e.target.files?.[0];
          if (file) void upload(file);
        }}
      />
      {state.status === "completed" ? (
        <p>Done — {state.fileId}</p>
      ) : null}
      {state.status === "error" ? <p>{state.message}</p> : null}
      <button type="button" onClick={reset}>
        Reset
      </button>
    </div>
  );
}

Options:

  • poll: true — poll status after upload (default false)
  • client — reuse a configured ReuploadClient

For server-side direct uploads (browser → your API → Reupload), use @reupload/sdk on the server — not this package.

Confirm before upload

ReuploadClient.uploadFile() and useReuploadUpload().upload() always start the upload when you call them — there is no built-in file-picker or auto-upload behavior.

For confirm-before-upload UX, use @reupload/react with immediateUpload={false}. The shared BeforeUploadHandler type is exported for optional async gates on confirm:

import type { BeforeUploadHandler } from "@reupload/client";

const onBeforeUpload: BeforeUploadHandler = async (files) => {
  return window.confirm(`Upload ${files.length} file(s)?`);
};

SolidStart / H3

Use the client in API route handlers or components — same as React. For file input in the browser:

import { createReuploadClientFromEnv } from "@reupload/client";

const client = createReuploadClientFromEnv();
await client.uploadFile(file);

SolidStart server routes that receive uploads should use @reupload/sdk/h3 instead.

Development

cd node-packages/reupload-client
npm install
npm run typecheck
npm test
npm run build

License

MIT