Node.js SDK
@devstorage/node is for backends that already hold the file bytes — queue workers, cron jobs, imports, server-side generation. It wraps the REST API with automatic multipart chunking for large files. For browser uploads in a Next.js app, use @devstorage/next instead.
Install
npm install @devstorage/nodeUpload
import { DevStorage } from "@devstorage/node";
const ds = new DevStorage({
apiKey: process.env.DEVSTORAGE_API_KEY!,
});
const file = await ds.upload(buffer, {
name: "report.pdf",
mimeType: "application/pdf",
metadata: { invoiceId: "inv_123" },
});
console.log(file.url);upload(body, options) accepts a Uint8Array (including Node Buffer), ArrayBuffer, or Blob. Files of 100 MiB or more are chunked through the multipart API automatically; a failed transfer aborts its session before the error is thrown.
Options
| Option | Description |
|---|---|
name | File name to record. Required. |
mimeType | MIME type of the body. Required. |
metadata | String key/value pairs stored with the file and echoed in webhooks. |
multipartThreshold | Bytes at/above which multipart is used. Default 100 MiB. |
signal | AbortSignal to cancel the upload. |
Manage files
// List (cursor-paginated, newest first)
const { files, nextCursor } = await ds.files.list({ limit: 50 });
const more = await ds.files.list({ limit: 50, cursor: nextCursor! });
// Get one file's record
const file = await ds.files.get("file_abc123");
// Delete the record and the stored object
await ds.files.delete("file_abc123");Errors
Every failure throws DevStorageError with the HTTP status and, when the API provides one, a machine-readable code:
import { DevStorage, DevStorageError } from "@devstorage/node";
try {
await ds.upload(bytes, { name: "big.mp4", mimeType: "video/mp4" });
} catch (err) {
if (err instanceof DevStorageError) {
console.error(err.status, err.code, err.message);
}
}Configuration
| Option | Description |
|---|---|
apiKey | Project API key (dsk_live_…). Required — pass it explicitly, e.g. from process.env.DEVSTORAGE_API_KEY. |
baseUrl | API host. Defaults to DEVSTORAGE_API_URL or https://api.devstorage.io. |