DEV Community

Alex Spinov
Alex Spinov

Posted on

Deno KV Has a Free API You Should Know About

Deno KV is a built-in key-value database that comes with the Deno runtime. No setup, no dependencies, no external services — just import and use.

Why Deno KV is Revolutionary

A developer needed a database for a small API. Setting up PostgreSQL meant Docker, migrations, connection pooling, and environment variables. With Deno KV, they added a database with zero setup — it's built right into the runtime.

Key Features:

  • Zero Setup — Built into Deno runtime, no installation needed
  • ACID Transactions — Full transactional support
  • Global Replication — Distributed across Deno Deploy edge network
  • Watch API — Real-time change notifications
  • Free Tier — Generous limits on Deno Deploy

Quick Start

const kv = await Deno.openKv()

// Set a value
await kv.set(["users", "alice"], { name: "Alice", email: "alice@example.com" })

// Get a value
const result = await kv.get(["users", "alice"])
console.log(result.value) // { name: "Alice", email: "alice@example.com" }
Enter fullscreen mode Exit fullscreen mode

Atomic Transactions

const kv = await Deno.openKv()

// Transfer money atomically
await kv.atomic()
  .check({ key: ["accounts", "alice"], versionstamp: aliceEntry.versionstamp })
  .set(["accounts", "alice"], { balance: aliceBalance - 100 })
  .set(["accounts", "bob"], { balance: bobBalance + 100 })
  .commit()
Enter fullscreen mode Exit fullscreen mode

List with Prefix

// List all users
const iter = kv.list({ prefix: ["users"] })
for await (const entry of iter) {
  console.log(entry.key, entry.value)
}
Enter fullscreen mode Exit fullscreen mode

Why Choose Deno KV

  1. Zero infrastructure — no databases to manage
  2. Built-in — no npm install, no config
  3. Edge-native — globally distributed on Deno Deploy

Check out Deno KV docs to get started.


Need data storage solutions? Check out my Apify actors or email spinov001@gmail.com for custom web scraping.

Top comments (0)