GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

KV

Save small values like settings under a key. Read them from any route.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: 'node',
    // Node supports shared stores and local files
    kv: true,
  },
})
nuxt.config.ts
Deploy on

Node / Docker: Redis / Postgres / fs-lite

Save and read by key

kv.set() saves a value under a key. kv.get() reads it back or returns null.

Check errors without try/catch

Each call returns [error, value]. Errors have a code, why, and fix.

Keep data apart

Declare named stores in your config and pick one with kv.store(name).

Same code on every host

Values stay on disk in development. On Cloudflare, Deno, Redis, Postgres, or Upstash, your routes do not change.

Counters and one-time values

setIfAbsent() writes a token once. increment() counts and getAndDelete() reads a value only once, on local files, Redis, a Database, or Upstash.

Many keys in one call

kv.getMany() reads a list of keys. kv.setMany() writes a list of values.

Run a job once at a time

kv.lock() lets one server run a cron job or a sync while the others skip it, on Redis, a Database, or Upstash. Local files lock across the processes of one host.

Know when to use a database

Use KV to read by key. Use Database for tables, joins, or queries.