Skip to content

ariesclark/cloudflare-kv-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: ""
    }
}

Releases

No releases published

Packages

No packages published