Storage

Configure KV storage, cache, and database connections.

Note

All examples on this page assume the following import in nitro.config.ts:

import { defineConfig } from "nitro";

#kv

  • Default: {}

KV storage configuration.

export default defineConfig({
  kv: {
    redis: {
      driver: "redis",
      url: "redis://localhost:6379",
    },
  },
});

Use the $development key to override mounts during development:

export default defineConfig({
  $development: {
    kv: {
      redis: {
        driver: "fs",
        base: "./data/redis", // use filesystem in development
      },
    },
  },
});

$development only applies to the development server. Use $prerender to override mounts while prerendering. A mount with a different driver replaces the whole mount, and one with the same driver has its options deep merged.

Note

Previously named storage, which still works as a deprecated alias. The deprecated devStorage option is replaced by kv inside $development (and $prerender).

Read more in Docs > Storage.

#cache

  • Default: {}

Cache storage and global default options for cached functions, handlers and cache route rules.

export default defineConfig({
  cache: {
    driver: "fs", // "memory" (default) | "fs" | "kv"
    fs: { dir: ".data/cache" },
    defaults: { maxAge: 60, swr: true },
  },
});
  • driver: memory (in-process LRU), fs (filesystem, Node.js compatible runtimes only) or kv (the kv storage layer). Defaults to kv when a cache KV mount point is configured, and memory otherwise.
  • memory: maxSize and maxBytes limits of the memory driver.
  • fs: dir of the fs driver (defaults to .data/cache).
  • defaults: global default options for every cache (maxAge, swr, staleMaxAge, maxResolveTime, base, and handler-only varies, allowQuery, allowCookies, allowAuthorization, sendCacheControl, cacheStatusHeader, maxBodySize).
Read more in Docs > Cache#cache Storage.

#database

Database connection configurations. Requires experimental.database: true.

export default defineConfig({
  database: {
    default: {
      connector: "sqlite",
      options: { name: "db" },
    },
  },
});
Read more in Docs > Database.

#devDatabase

Database connection configuration overrides for development mode.

export default defineConfig({
  devDatabase: {
    default: {
      connector: "sqlite",
      options: { name: "db-dev" }, // separate dev database
    },
  },
});

Nitro  builds full-stack servers that deploy anywhere.