ViteHub

KV

Read and write key-value data through one portable runtime handle across Vite, Nitro, and Nuxt.

@vitehub/kv gives Vite, Nitro, and Nuxt apps one kv handle for application state that fits a key-value shape.

Use KV when route code needs to read or write small JSON-serializable values without carrying provider-specific SDK calls through the app. The provider choice stays in config. Runtime code keeps the same kv.get(), kv.set(), and kv.del() calls.

import { kv } from '@vitehub/kv'

export default defineEventHandler(async () => {
  await kv.set('settings', {
    theme: 'system',
    onboardingComplete: true,
  })

  return { ok: true }
})

What KV Solves

Provider storage SDKs are useful, but they couple route code to deployment infrastructure.

KV puts the provider behind the Nitro storage mount:

Portable runtime calls

Use the same kv handle for local development, Cloudflare KV, and Upstash-backed Vercel deployments.

Config-based routing

Pick fs-lite, cloudflare-kv-binding, or upstash in config or let ViteHub infer the driver.

Nitro storage backing

Mount the active driver as Nitro storage at kv, then expose a small typed wrapper.

Secret-safe Upstash setup

Keep Upstash credentials in runtime environment variables instead of serializing them into build output.

One Portable Flow

The same shape works across supported frameworks:

  1. Install @vitehub/kv.
  2. Register hubKv(), @vitehub/kv/nitro, or @vitehub/kv/nuxt.
  3. Choose a driver or let ViteHub resolve one.
  4. Import kv from @vitehub/kv in server/runtime code.
  5. Read and write values with get, set, has, del, keys, and clear.
Provider-specific setup belongs in framework config and deployment environment variables. Application call sites should stay provider-neutral unless you intentionally pass driver-specific options.

Driver Routing

ViteHub resolves KV config in this order:

PrioritySignalResolved driver
1Explicit kv.driverThe configured driver
2KV_REST_API_URL and KV_REST_API_TOKENupstash
3Vercel hostingupstash
4Cloudflare hostingcloudflare-kv-binding
5Everything elsefs-lite

Explicit config always wins. That means you can force fs-lite locally, force Cloudflare for a Worker, or force Upstash for any runtime.

Framework Support

Nuxt registers @vitehub/kv/nuxt, which installs the Nitro module and forwards top-level kv config to Nitro.

Supported Providers

Cloudflare
Use Cloudflare KV bindings with Workers or Pages.
Vercel
Use Vercel with the Upstash-backed KV driver.

Start Here

Start with Quickstart for a complete local setup. Use the primitive comparison when you are deciding between KV, Blob, Queue, Sandbox, or a database.

Next Steps

Quickstart
Configure KV and read back a settings value.
Usage
Use keys, prefixes, deletes, lists, clears, and provider-specific options.
Runtime API
Review exports, config shapes, methods, and generated config imports.
Troubleshooting
Fix missing mounts, provider routing, bindings, and Upstash credentials.
NuxtHub migration
Move existing NuxtHub KV apps to ViteHub KV.
Copyright © 2026