Node.js and TypeScript media SDK

dreep is the official Node.js and TypeScript SDK for Dreep. Upload files from your server, presign direct uploads for browsers, and build transform and signed URLs without a network call. It has zero dependencies and needs Node.js 18 or later.

How browser uploads work

Browsers never hold your API key. Your server presigns a single-use upload URL, valid for 10 minutes, and the browser PUTs the file there directly.

  1. 1

    Browser asks

    name, type and size

  2. 2

    Server presigns

    presignUpload()

  3. 3

    Browser PUTs

    bytes to uploadUrl

  4. 4

    Server confirms

    confirmUpload()

  5. 5

    Asset ready

    CDN URL returned

Until confirmUpload() runs, the asset stays pending.

Install and upload

Keep the API key in an environment variable on your server. The cURL tab shows the request the SDK makes for you.

import fs from "node:fs";
import { Dreep } from "dreep";

const dreep = new Dreep({ apiKey: process.env.DREEP_API_KEY });

// Server upload, converted to WebP before it is stored
const asset = await dreep.upload({
  file: fs.createReadStream("hero.jpg"),
  transform: { width: 1200, format: "webp" },
});
dreep.url(asset, { width: 400 }); // no network call

// Browser upload: presign here, the browser PUTs to uploadUrl
const { id, uploadUrl } = await dreep.presignUpload({ filename, contentType, sizeBytes });
const confirmed = await dreep.confirmUpload({ id });

Why use the package

Zero dependencies

Built on native fetch and node:crypto, so nothing else lands in your lockfile.

Typed transforms

An invalid fit or rotate value is a compile error rather than an ignored query parameter.

Server-only by design

The constructor throws in a browser, so your API key never ships to clients.

Frequently asked questions

Does the dreep package work with both import and require?

Yes. It ships ESM and CommonJS builds with type declarations for both.

How do I upload from the browser without exposing my API key?

Call presignUpload() on your server, let the browser PUT the file to uploadUrl, then call confirmUpload({ id }) on your server.

Does url() make a request to Dreep?

No. It appends query parameters to the asset's CDN URL. The variant is generated the first time that URL is requested and cached after that.

What is the difference between transform on upload and url()?

A transform passed to upload() runs once before storage and replaces the original. url() keeps the original and derives any size from it on request.

Related

Install dreep and upload your first file

Create a free project, copy an API key and run npm install dreep.