Cloudflare KV Storage 📦
A dead simple client for Cloudflare's KV storage.
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: ""
}
}