cloudflare-kv-storage
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Cloudflare KV Storage 📦

A dead simple client for Cloudflare's KV storage.

Maintenance GitHub GitHub issues GitHub code size in bytes npm downloads npm bundle size

Usage

import { CloudflareKV } from "cloudflare-kv-storage";

const kv = new CloudflareKV({
	accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
	namespaceId: process.env.CLOUDFLARE_NAMESPACE_ID,
	accessToken: process.env.CLOUDFLARE_ACCESS_TOKEN
});

// or you can directly import "kv" which uses the 
// environment variables by default.
import { kv } from "cloudflare-kv-storage";

await kv.set("foo", "hello", { expiration_ttl: "10m" });
await kv.set("bar", "world", { expiration: Date.now() + 10000 });
await kv.set("baz", "bin");

await kv.get("bar") // "world"
await kv.delete("foo");

await kv.list();
// will return something like:
{
    result: [
        {
            name: "bar",
            expiration: 1646499225
        },
        {
            name: "baz"
        }
    ],
    success: true,
    errors: [],
    messages: [],
    result_info: {
        count: 2,
        cursor: ""
    }
}

Package Sidebar

Install

npm i cloudflare-kv-storage

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

11.6 kB

Total Files

5

Last publish

Collaborators

  • ariesclark