ViteHub

KV quickstart

Register KV, write a settings value, read it back, and verify the JSON response.

This guide creates one settings key. The write route stores a JSON value and the read route returns it through the same kv handle.

The examples use the local fs-lite driver so you can verify the app before choosing Cloudflare or Vercel.

Prompt
Set up @vitehub/kv in this app.

- Install @vitehub/kv
- Register hubKv(), @vitehub/kv/nitro, or @vitehub/kv/nuxt
- Configure kv.driver as fs-lite for local development
- Add routes that call kv.set('settings', value) and kv.get('settings')
- Return the stored value as JSON

Docs: /docs/vite/kv/quickstart, /docs/nitro/kv/quickstart, or /docs/nuxt/kv/quickstart

Install KV

pnpm add @vitehub/kv

Register the integration

Register the Vite plugin and choose the local driver:

vite.config.ts
import { defineConfig } from 'vite'
import { hubKv } from '@vitehub/kv/vite'

export default defineConfig({
  plugins: [hubKv()],
  kv: {
    driver: 'fs-lite',
    base: '.data/kv',
  },
})

Write a value

Use the kv handle from server code that runs with the Nitro storage mount:

src/main.ts
import { H3, serve } from 'h3'
import { kv } from '@vitehub/kv'

const app = new H3()
  .put('/api/settings', async () => {
    await kv.set('settings', { enabled: true })
    return { ok: true }
  })
  .get('/api/settings', async () => {
    return { settings: await kv.get('settings') }
  })

serve(app)

Read the value

Verify the response

Write the value:

curl -X PUT http://localhost:3000/api/settings

Read it back:

curl http://localhost:3000/api/settings

Expected response:

{
  "settings": {
    "enabled": true
  }
}

Hosted Providers

The route code stays the same when you switch providers. Change config and deployment environment only:

Cloudflare
Configure the Cloudflare KV binding driver.
Vercel
Configure the Upstash-backed Vercel path.

Next Steps

  • Use Usage for key naming, prefixes, and common methods.
  • Use Runtime API for exact config shapes.
  • Use Troubleshooting if the runtime mount or provider credentials are missing.
Copyright © 2026