Cloudflare KV
Use the Cloudflare provider when runtime KV should read and write through a Cloudflare KV namespace.
Cloudflare needs a KV binding. ViteHub defaults that binding name to KV and can add the Wrangler namespace entry when namespaceId is available.
Configure KV
Register the Nuxt module and set kv.driver to cloudflare-kv-binding:
export default defineNuxtConfig({
modules: ['@vitehub/kv/nuxt'],
kv: {
driver: 'cloudflare-kv-binding',
binding: 'KV',
namespaceId: '<kv-namespace-id>',
},
})
Set the Namespace ID
Pass namespaceId in config:
kv: {
driver: 'cloudflare-kv-binding',
namespaceId: '<kv-namespace-id>',
}
Or set KV_NAMESPACE_ID in the build environment:
KV_NAMESPACE_ID=<kv-namespace-id>
When namespaceId is present, the Nitro module adds the namespace to Cloudflare Wrangler config:
cloudflare: {
wrangler: {
kv_namespaces: [
{ binding: 'KV', id: '<kv-namespace-id>' },
],
},
}
Use a Custom Binding Name
The default binding is KV. Set binding when the Cloudflare resource uses another name:
kv: {
driver: 'cloudflare-kv-binding',
binding: 'APP_KV',
namespaceId: '<kv-namespace-id>',
}
The runtime driver reads from that Cloudflare binding.
Let Hosting Select Cloudflare
When hosting resolves to Cloudflare and no explicit driver is set, ViteHub selects cloudflare-kv-binding automatically:
export default defineNitroConfig({
modules: ['@vitehub/kv/nitro'],
})
Explicit kv.driver still wins. Use explicit config when you want local fs-lite behavior or need a custom binding.
Verify the Provider
Write a value:
curl -X PUT https://<your-worker>/api/settings
Read it back:
curl https://<your-worker>/api/settings
Expected response:
{
"settings": {
"enabled": true
}
}
Common Failures
| Symptom | Cause | Fix |
|---|---|---|
Reads always return null after deploy | The Worker is bound to the wrong namespace or binding name. | Check binding, namespaceId, and Cloudflare deployment config. |
| Local development stores files instead of Cloudflare data | Hosting was not detected as Cloudflare. | Set kv.driver to cloudflare-kv-binding explicitly. |
| Wrangler namespace config is missing | namespaceId was not configured and KV_NAMESPACE_ID was not set. | Add namespaceId or set KV_NAMESPACE_ID. |

