Registry / storage / unstorage

unstorage

JSON →
library1.17.5jsnpmunverified

Unstorage is an async key-value storage library for JavaScript environments, version 1.17.5, with frequent releases. It provides a universal storage layer supporting browser, Node.js, and Workers, with over 20 built-in drivers (memory, Redis, FS, S3, Cloudflare KV, etc.). Key differentiators: Unix-style driver mounting to combine storages, tree-shakable core (~2KB), automatic JSON serialization, binary support, watchable storage, and HTTP server. Unlike other libraries, it emphasizes cross-environment compatibility and minimal dependencies, with optional driver packages.

npm install unstorage
INSTALL
IMPORT
SIG · UNSTORAGE
U
unstorage
storagejavascriptv1.17.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createStorage
import { createStorage } from 'unstorage'
import createStorage from 'unstorage'
createStorage is a named export, not default
defineDriver
import { defineDriver } from 'unstorage'
Used to create custom drivers
prefixStorage
import { prefixStorage } from 'unstorage'
import prefixStorage from 'unstorage'
Named export for prefixing storage keys
default
import storage from 'unstorage'
import { default as storage } from 'unstorage'
There is no default export; you must use named exports or create a storage instance.

Creates a storage instance (default in-memory), sets, gets, and deletes a JSON object.

import { createStorage } from 'unstorage'; const storage = createStorage({ driver: process.env.STORAGE_DRIVER ?? 'memory', }); async function main() { await storage.setItem('session:user', { name: 'Alice', role: 'admin' }); const user = await storage.getItem('session:user'); console.log(user); // { name: 'Alice', role: 'admin' } await storage.del('session:user'); } main().catch(console.error);
Debug
Known issues
breakingBefore v1.0, createStorage returned a 'snapshot' method; now it's a separate utility.
fix
Import snapshot from 'unstorage/utils' or use storage.getItems/setItems explicitly.
affects: <1.0.0
deprecatedDriver export 'cloudflare-kv-binding' is deprecated; use 'cloudflare:kv-binding' instead.
fix
Replace 'cloudflare-kv-binding' with 'cloudflare:kv-binding' in driver config.
affects: >=1.5.0
gotchaBrowsers: IndexedDB driver requires idb-keyval package but is not auto-installed; must be added as a dependency.
fix
Install idb-keyval: npm install idb-keyval
affects: >=1.0.0
gotchaIn-memory driver does not persist data across server restarts; explicitly configure a persistent driver for production.
fix
Use a driver like 'fs', 'redis', or 'cloudflare:kv-binding'.
affects: >=1.0.0
gotchaDriver options (e.g., Redis connection) are passed directly to the underlying driver, not bundled; ensure correct driver package installed.
fix
Install the appropriate driver package (e.g., ioredis for Redis).
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'unstorage' or its corresponding type declarations.
unstorage is not installed or missing TypeScript definitions.
fix
npm install unstorage (or yarn/pnpm add).
TypeError: createStorage is not a function
Default import instead of named import.
fix
Use import { createStorage } from 'unstorage'.
Error: Cannot find module 'ioredis'
Missing driver dependency for Redis.
fix
npm install ioredis
No driver was specified. Using the default built-in memory driver.
No driver configured in createStorage options.
fix
Add a driver: createStorage({ driver: 'fs', options: { base: './data' } }).
Upgrade
Version history
1.17.5latest on npm
Audit
Dependencies
@azure/app-configurationoptionalOptional driver for Azure App Configuration
@azure/cosmosoptionalOptional driver for Azure Cosmos DB
@azure/data-tablesoptionalOptional driver for Azure Tables
@azure/identityoptionalOptional driver for Azure Identity
@azure/keyvault-secretsoptionalOptional driver for Azure Key Vault
@azure/storage-bloboptionalOptional driver for Azure Blob Storage
@capacitor/preferencesoptionalOptional driver for Capacitor Preferences
@deno/kvoptionalOptional driver for Deno KV
@netlify/blobsoptionalOptional driver for Netlify Blobs
@planetscale/databaseoptionalOptional driver for PlanetScale
@upstash/redisoptionalOptional driver for Upstash Redis
@vercel/bloboptionalOptional driver for Vercel Blob
@vercel/functionsoptionalOptional driver for Vercel Functions
@vercel/kvoptionalOptional driver for Vercel KV
aws4fetchoptionalOptional driver for AWS S3
db0optionalOptional driver for database (db0)
idb-keyvaloptionalOptional driver for IndexedDB
ioredisoptionalOptional driver for Redis
uploadthingoptionalOptional driver for UploadThing
Agent activity
28 hits · last 30 days
node
26
Anthropic
1
Resources