Nitro
Use this skill when work touches Nitro v3 (nitro.build): scaffolding, Vite integration, file routes, server entry, storage/cache, presets, or deploying the same codebase to Node, Bun, Deno, workers, or serverless.
Nitro compiles routes at build time (no runtime router in the bundle). Production output is .output/ — deploy that artifact, not the source tree.
Workflow
- Inspect the local Nitro surface:
- Package:
nitrov3 (notnitropackv2). Snapshot3.0.260903-beta. Node ≥ 20. - Config:
nitro.config.ts(defineConfigfrom"nitro"), and/ornitrokey +nitro()from"nitro/vite"invite.config.ts. - Layout:
serverDir(falsedefault; often"server"in Vite apps),routes/,middleware/,plugins/,public/,assets/, optionalserver.ts/server.node.ts,renderer. - Preset: explicit
preset,NITRO_PRESET, or CI auto-detect. ConfirmcompatibilityDatewhen provider features matter.
- Package:
- Refresh current docs when APIs, presets, experimental flags, or v2→v3 migration matter. Start from source-map.md.
- Route the work:
- Scaffold, Vite,
defineConfig, runtime config, dirs: setup-config.md. - Filesystem routes, methods, middleware,
routeRules: routing.md. server.ts, frameworks, Node vs Web format: server-entry.md.- Cache, unstorage, SQL (experimental): cache-storage-database.md.
- Plugins, request lifecycle, errors: plugins-lifecycle.md.
- Public/server assets, renderer, SPA: assets-renderer.md.
- Tasks, OpenAPI, WebSocket, SSE: tasks-openapi-websocket.md.
- Presets, platforms,
.output, env: deploy.md. - v2 (
nitropack) → v3: migration.md.
- Scaffold, Vite,
- Preserve the repo’s existing framework entry and preset unless the user asks to change host or migrate.
- Verify with a production build for the actual preset, then smoke the host-specific entry (see production.md).
Core Judgment
- Prefer
bunx create-nitro-app,bunx nitro,bunx vite. Keep registry names (nitro, dist-tags) as package facts. - Handlers:
defineHandlerfrom"nitro"; H3event. Return JSON, string,Response, or streams. One handler per file. - Filesystem:
routes/(androutes/api/). Method suffixhello.get.ts. Params[id], catch-all[...]or[...].ts. Groups(admin)do not appear in the URL. Env suffixes.dev/.prod/.prerender. - Server entry runs as
/**for unmatched routes (specificroutes/win). Returning a response stops the chain; returning nothing continues to renderer. Webfetchapps useserver.ts; Node(req, res)useserver.node.ts(srvx). Elysia:export default app.compile(). Fastify:await app.ready(); export default app.routing. - Do not put secrets in client Vite env. Server secrets go in
runtimeConfigandNITRO_(or customruntimeConfig.nitro.envPrefix) platform env..env/.env.localload innitro devonly. - Cache:
defineCachedHandler/defineCachedFunctionfrom"nitro/cache". Only GET/HEAD. Default SWR on. Headers dropped unlessvaries. Production cache mount defaults to memory — mount Redis/KV/fsonstorage.cachefor persistence. On edge, passeventfirst into cached functions sowaitUntilcan finish writes. - Storage:
useStoragefrom"nitro/storage". Root mount is in-memory. Persist viastorage/devStorage. Server files live underassets:server/assets/server. - Database (
experimental.database) and tasks (experimental.tasks) are experimental. OpenAPI is experimental; keep production UIs off or authenticated (openAPI.production). - WebSocket:
features.websocket: true+defineWebSocketHandler. SSE:createEventStreamfrom"nitro/h3". - Deploy: one codebase; switch with
preset/NITRO_PRESET. Prefer auto-detect in CI. Cloudflare: prefercloudflare_moduleover Pages unless Pages-only features are required. Node default:node_server→node .output/server/index.mjs. Do not treatvite previewas production. - Plugins:
definePlugin(not v2defineNitroPlugin). Plugin functions are sync; hooks may be async. Prefix plugin filenames for order.
Verification
Prefer repository-owned commands. For meaningful Nitro work, cover the relevant subset from production.md:
bunx nitro --version/ lockfilenitromajor (v3 vsnitropackv2).bun run dev(orvitewithnitro()): hit new routes, methods, and middleware order.bunx nitro build(orvite build) for the target preset; inspect.output/.- Run the preset entry locally (
node/bun/ wrangler) and smoke health, cookies, proxy headers, staticpublic/, and API JSON. - Cache: confirm GET cached, POST bypassed,
variesif multi-tenant. - Platform: env
NITRO_*, bindings, cron/scheduledTasks, WebSocket, and ISR/SWRrouteRuleson that host.
Report which checks ran, which did not, and any v3-beta or preset assumptions that remain.