| icon | ri:settings-3-line |
|---|
:read-more{to="/guide/configuration"}
Use 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.
- Default:
3{lang=ts} (1{lang=ts} when the testing environment is detected)
Log verbosity level. See consola for more information.
- Default:
{ nitro: { ... }, ...yourOptions }{lang=ts}
Server runtime configuration.
Note:: nitro namespace is reserved.
Deployment 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.
- Default:
{}
Enable experimental features.
Enable /_scalar, /_swagger and /_openapi.json endpoints.
- Default:
false
To 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"
}
}
}Enable WASM support
When enabled, legacy (unstable) experimental rollup externals algorithm will be used.
- Default:
{}
New features pending for a major version to avoid breaking changes.
Uses built-in SWR functionality (using caching layer and storage) for Netlify and Vercel presets instead of falling back to ISR behavior.
- Default:
{}
Storage configuration, read more in the Storage Layer section.
- Default:
false{lang=ts}
Enable timing information:
- Nitro startup time log
Server-Timingheader on HTTP responses
Path to main render (file should export an event handler as default)
- Type:
boolean|'node'{lang=ts} |'deno'{lang=ts} - Default: depends of the deployment preset used.
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.
- Default:
false{lang=ts}
If enabled, disabled .output/public directory creation. Skipping to copy public/ dir and also disables pre-rendering.
Public 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.
- Default:
{ gzip: false, brotli: false }{lang=ts}
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.mpegurl
Assets can be accessed in server logic and bundled in production. Read more.
- Default:
{ watch: [] }{lang=ts}
Dev server options. You can use watch to make the dev server reload if any file changes in specified paths.
Watch options for development mode. See chokidar for more information.
Auto import options. See unimport for more information.
- Default:
[]
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.
- Default:
{}
A map from dynamic virtual import names to their contents or an (async) function that returns it.
Default: /{lang=ts} (or NITRO_APP_BASE_URL environment variable if provided)
Server's main base URL.
- Default :
/api
Changes the default api base URL prefix.
Server handlers and routes.
If server/routes/, server/api/ or server/middleware/ directories exist, they will be automatically added to the handlers array.
Regular 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 { defineEventHandler } from 'h3'
export default defineNitroConfig({
devHandlers: [
{
route: '/',
handler: defineEventHandler((event) => {
console.log(event)
})
}
]
})::note{type=info}
Note that defineEventHandler is a helper function from h3 library.
::
Proxy 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.
Path 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:
export default defineNitroConfig({
errorHandler: "~/error",
});export default defineNitroErrorHandler((error, event) => {
setResponseHeader(event, 'Content-Type', 'text/plain')
return send(event, '[custom error handler] ' + error.stack)
});🧪 Experimental!
Route options. It is a map from route pattern (following radix3) to route options.
How matching and precedence work:
- Nitro matches the incoming path against all patterns and deep-merges every matching rule.
- More specific matches override less specific ones. For example,
/blog/postoverrides/blog/**, which overrides/**. - The match is performed against the path only (without the query string) and without the configured
app.baseURL.
When cache option is set, handlers matching pattern will be automatically wrapped with defineCachedEventHandler.
See the Cache API for all available cache options.
::note
swr: true|number is shortcut for cache: { swr: true, maxAge: number }
::
Available keys (summary):
cache: CachedEventHandlerOptions | false — server-side caching (see Cache guide)headers: Record<string,string> — set response headersredirect: string | { to; statusCode? } — server redirect; wildcard/**tail can be appended to destination; query params are preserved when the destination is not a wildcard patternprerender: boolean — add exact routes to prerender queue at build;falseexplicitly disablesproxy: string | { to } & ProxyOptions — proxy requests; wildcard/**tail can be appended to destination; query params are preserved when the destination is not a wildcard patternisr: number | boolean | object — ISR/Revalidation on supported platformscors: boolean — shortcut to add permissive CORS headersswr: boolean | number — legacy shortcut forcache: { swr: true, maxAge? }static: boolean | number — legacy alias; preferisr
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/**' },
}Default:
{
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.htmlThis 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.
Project workspace root directory.
The workspace (e.g. pnpm workspace) directory is automatically detected when the workspaceDir option is not set.
Project main directory.
- Default: (same as
rootDir)
Project source directory. Same as rootDir unless specified.
Root directory for api, routes, plugins, utils, public, middleware, assets, and tasks folders.
- Default: (source directory when empty array)
List of directories to scan and auto-register files, such as API routes.
- Default :
api
Defines a different directory to scan for api route handlers.
- Default :
routes
Defines a different directory to scan for route handlers.
- Default:
.nitro
nitro's temporary working directory for generating build-related files.
- Default:
{ dir: '.output', serverDir: '.output/server', publicDir: '.output/public' }
Output directories for production bundle.
- Default:
truefor development andfalsefor production.
Default: { generateTsConfig: true }
Additional node_modules to search when resolving a module. By default user directory is added.
nitro hooks. See hookable for more information.
Preview and deploy command hints are usually filled by deployment presets.
A custom error handler function for development errors.
Additional rollup configuration.
Rollup entry.
Options for unenv preset.
Rollup aliases options.
- Default:
false
Minify bundle.
Avoid creating chunks.
Enable source map generation. See options
- Default:
true
Specify 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.
If enabled, will analyze server bundle after build using rollup-plugin-visualizer. You can also pass your custom options.
Default: ['unenv/polyfill/', 'node-fetch-native/polyfill']
Rollup specific option. Specifies module imports that have side-effects
Rollup specific option.
Rollup specific option. Specifies additional configuration for the rollup CommonJS plugin.
The options for the firebase functions preset. See Preset Docs
The options for the vercel preset. See Preset Docs
The options for the cloudflare preset. See Preset Docs