presetUse preset option NITRO_PRESET environment variable for custom production preset.
Preset for development mode is always nitro_dev and default node_server for production building a standalone Node.js server.
The preset will automatically be detected when the preset option is not set and running in known environments.
logLevel3 (1 when the testing environment is detected)Log verbosity level. See consola for more information.
runtimeConfig{ nitro: { ... }, ...yourOptions }Server runtime configuration.
Note:: nitro namespace is reserved.
compatibilityDateDeployment providers introduce new features that Nitro presets can leverage, but some of them need to be explicitly opted into.
Set it to latest tested date in YY-MM-DD format to leverage latest preset features.
If this configuration is not provided, Nitro will continue using the current (v2.9) behavior for presets and show a warning.
experimental{}Enable experimental features.
openAPIEnable /_scalar, /_swagger and /_openapi.json endpoints.
falseTo define the OpenAPI specification on your routes, take a look at defineRouteMeta
You can pass an object on the root level to modify your OpenAPI specification:
openAPI: {
meta: {
title: 'My Awesome Project',
description: 'This might become the next big thing.',
version: '1.0'
}
}
These routes are disabled by default in production. To enable them, use the production key.
"runtime" allows middleware usage, and "prerender" is the most efficient because the JSON response is constant.
openAPI: {
// IMPORTANT: make sure to protect OpenAPI routes if necessary!
production: "runtime", // or "prerender"
}
If you like to customize the Scalar integration, you can pass a configuration object like this:
openAPI: {
ui: {
scalar: {
theme: 'purple'
}
}
}
Or if you want to customize the endpoints:
openAPI: {
route: "/_docs/openapi.json",
ui: {
scalar: {
route: "/_docs/scalar"
},
swagger: {
route: "/_docs/swagger"
}
}
}
wasmEnable WASM support
future{}New features pending for a major version to avoid breaking changes.
nativeSWRUses built-in SWR functionality (using caching layer and storage) for Netlify and Vercel presets instead of falling back to ISR behavior.
storage{}Storage configuration, read more in the Storage Layer section.
renderer{ entry } points to main render entry (file should export an event handler as default)
serveStaticboolean | 'node' | 'deno'Serve public/ assets in production.
Note: It is highly recommended that your edge CDN (Nginx, Apache, Cloud) serves the .output/public/ directory instead of enabling compression and higher lever caching.
noPublicDirfalseIf enabled, disabled .output/public directory creation. Skipping to copy public/ dir and also disables pre-rendering.
publicAssetsPublic asset directories to serve in development and bundle in production.
If a public/ directory is detected, it will be added by default, but you can add more by yourself too!
It's possible to set Cache-Control headers for assets using the maxAge option:
publicAssets: [
{
baseURL: "images",
dir: "public/images",
maxAge: 60 * 60 * 24 * 7, // 7 days
},
],
The config above generates the following header in the assets under public/images/ folder:
cache-control: public, max-age=604800, immutable
The dir option is where your files live on your file system; the baseURL option is the folder they will be accessible from when served/bundled.
compressPublicAssets{ gzip: false, brotli: false }If enabled, Nitro will generate a pre-compressed (gzip and/or brotli) version of supported types of public assets and prerendered routes larger than 1024 bytes into the public directory. The best compression level is used. Using this option you can support zero overhead asset compression without using a CDN.
List of compressible MIME types:
application/dash+xmlapplication/eotapplication/fontapplication/font-sfntapplication/javascriptapplication/jsonapplication/opentypeapplication/otfapplication/pdfapplication/pkcs7-mimeapplication/protobufapplication/rss+xmlapplication/truetypeapplication/ttfapplication/vnd.apple.mpegurlapplication/vnd.mapbox-vector-tileapplication/vnd.ms-fontobjectapplication/wasmapplication/xhtml+xmlapplication/xmlapplication/x-font-opentypeapplication/x-font-truetypeapplication/x-font-ttfapplication/x-httpd-cgiapplication/x-javascriptapplication/x-mpegurlapplication/x-opentypeapplication/x-otfapplication/x-perlapplication/x-ttffont/eotfont/opentypefont/otffont/ttfimage/svg+xmltext/csstext/csvtext/htmltext/javascripttext/jstext/plaintext/richtexttext/tab-separated-valuestext/xmltext/x-componenttext/x-java-sourcetext/x-scriptvnd.apple.mpegurlserverAssetsAssets can be accessed in server logic and bundled in production. Read more.
devServer{ watch: [] }Dev server options. You can use watch to make the dev server reload if any file changes in specified paths.
watchOptionsWatch options for development mode. See chokidar for more information.
importsAuto import options. See unimport for more information.
plugins[]An array of paths to nitro plugins. They will be executed by order on the first initialization.
Note that Nitro auto-register the plugins in the plugins/ directory, learn more.
virtual{}A map from dynamic virtual import names to their contents or an (async) function that returns it.
baseURLDefault: / (or NITRO_APP_BASE_URL environment variable if provided)
Server's main base URL.
apiBaseURL/apiChanges the default API base URL prefix.
handlersServer handlers and routes.
If server/routes/, server/api/ or server/middleware/ directories exist, they will be automatically added to the handlers array.
devHandlersRegular handlers refer to the path of handlers to be imported and transformed by rollup.
There are situations in that we directly want to provide a handler instance with programmatic usage.
We can use devHandlers but note that they are only available in development mode and not in production build.
For example:
import { defineNitroConfig } from "nitro/config";
import { defineHandler } from "nitro/h3";
export default defineNitroConfig({
devHandlers: [
{
route: '/',
handler: defineHandler((event) => {
console.log(event);
}),
},
],
});
devProxyProxy configuration for development server.
You can use this option to override development server routes and proxy-pass requests.
{
devProxy: {
'/proxy/test': 'http://localhost:3001',
'/proxy/example': { target: 'https://example.com', changeOrigin: true }
}
}
See httpxy for all available target options.
errorHandlerPath to a custom runtime error handler. Replacing nitro's built-in error page.
The error handler is given an H3Error and H3Event. If the handler returns a promise it is awaited.
The handler is expected to send a response of its own.
Below is an example where a plain-text response is returned using h3's functions.
Example:
import { defineNitroConfig } from "nitro/config";
export default defineNitroConfig({
errorHandler: "~/error",
});
export default defineNitroErrorHandler((error, event) => {
setResponseHeader(event, 'Content-Type', 'text/plain')
return send(event, '[custom error handler] ' + error.stack)
});
routeRules🧪 Experimental!
Route options. It is a map from route pattern (following rou3) to route options.
When cache option is set, handlers matching pattern will be automatically wrapped with defineCachedEventHandler.
See the Cache API for all available cache options.
swr: true|number is shortcut for cache: { swr: true, maxAge: number }Example:
routeRules: {
'/blog/**': { swr: true },
'/blog/**': { swr: 600 },
'/blog/**': { static: true },
'/blog/**': { cache: { /* cache options*/ } },
'/assets/**': { headers: { 'cache-control': 's-maxage=0' } },
'/api/v1/**': { cors: true, headers: { 'access-control-allow-methods': 'GET' } },
'/old-page': { redirect: '/new-page' }, // uses status code 307 (Temporary Redirect)
'/old-page2': { redirect: { to:'/new-page2', statusCode: 301 } },
'/old-page/**': { redirect: '/new-page/**' },
'/proxy/example': { proxy: 'https://example.com' },
'/proxy/**': { proxy: '/api/**' },
}
prerenderDefault:
{
autoSubfolderIndex: true,
concurrency: 1,
interval: 0,
failOnError: false,
crawlLinks: false,
ignore: [],
routes: [],
retry: 3,
retryDelay: 500
}
Prerendered options. Any route specified will be fetched during the build and copied to the .output/public directory as a static asset.
Any route (string) that starts with a prefix listed in ignore or matches a regular expression or function will be ignored.
If crawlLinks option is set to true, nitro starts with / by default (or all routes in routes array) and for HTML pages extracts <a> tags and prerender them as well.
You can set failOnError option to true to stop the CI when an error if Nitro could not prerender a route.
The interval and concurrency options lets you control the speed of pre-rendering, can be useful to avoid hitting some rate-limit if you call external APIs.
Set autoSubfolderIndex lets you control how to generate the files in the .output/public directory:
# autoSubfolderIndex: true (default)
/about -> .output/public/about/index.html
# autoSubfolderIndex: false
/about -> .output/public/about.html
This option is useful when your hosting provider does not give you an option regarding the trailing slash.
The prerenderer will attempt to render pages 3 times with a delay of 500ms. Use retry and retryDelay to change this behavior.
workspaceDirProject workspace root directory.
The workspace (e.g. pnpm workspace) directory is automatically detected when the workspaceDir option is not set.
rootDirProject main directory.
srcDirrootDir)Project source directory. Same as rootDir unless specified.
Root directory for api, routes, plugins, utils, public, middleware, assets, and tasks folders.
scanDirsList of directories to scan and auto-register files, such as API routes.
apiDirapiDefines a different directory to scan for api route handlers.
routesDirroutesDefines a different directory to scan for route handlers.
buildDir.nitronitro's temporary working directory for generating build-related files.
output{ dir: '.output', serverDir: '.output/server', publicDir: '.output/public' }Output directories for production bundle.
devtrue for development and false for production.⚠️ Caution! This is an advanced configuration. Things can go wrong if misconfigured.
typescriptDefault: { generateTsConfig: true }
nodeModulesDirs⚠️ Caution! This is an advanced configuration. Things can go wrong if misconfigured.
Additional node_modules to search when resolving a module. By default user directory is added.
hooks⚠️ Caution! This is an advanced configuration. Things can go wrong if misconfigured.
nitro hooks. See hookable for more information.
commands⚠️ Caution! This is an advanced configuration. Things can go wrong if misconfigured.
Preview and deploy command hints are usually filled by deployment presets.
devErrorHandler⚠️ Caution! This is an advanced configuration. Things can go wrong if misconfigured.
A custom error handler function for development errors.
rollupConfigAdditional rollup configuration.
entryRollup entry.
unenvOptions for unenv preset.
aliasRollup aliases options.
minifyfalseMinify bundle.
inlineDynamicImportsAvoid creating chunks.
sourceMapEnable source map generation. See options
truenodeSpecify whether the build is used for Node.js or not. If set to false, nitro tries to mock Node.js dependencies using unenv and adjust its behavior.
moduleSideEffectsDefault: ['unenv/polyfill/']
Rollup specific option. Specifies module imports that have side-effects
replaceRollup specific option.
commonJSRollup specific option. Specifies additional configuration for the rollup CommonJS plugin.
firebaseThe options for the firebase functions preset. See Preset Docs
vercelThe options for the vercel preset. See Preset Docs
cloudflareThe options for the cloudflare preset. See Preset Docs