Configuration
You can customize your Nitro server with single configuration file: nitro.config.ts
.
All deployment providers are built on the same options API.
If you are using Nuxt, use the nitro
option in your Nuxt config.
export default defineNitroConfig({ // Nitro options})
Read all the available options to configure Nitro.
Nitro loads the configuration using unjs/c12, giving more possibilities such as using .nitrorc
.
timing=true
Runtime Configuration
Nitro provides a runtime config API to expose configuration within your application, with the ability to update it at runtime by setting environment variables.
To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your configuration file.
Example:
export default defineNitroConfig({ runtimeConfig: { helloThere: "foobar", }})
You can now access the runtime config using useRuntimeConfig(event)
.
Example:
export default defineEventHandler((event) => { return useRuntimeConfig(event).helloThere // foobar});
useRuntimeConfig(event)
within event handlers and utilities and avoid calling it in ambient global contexts.Environment Variables
Nitro supports defining environment variables using .env
file in development (use platform variables for production).
Create an .env
file in your project root:
TEST="123"
You can universally access environment variables using import.meta.env.TEST
or process.env.TEST
.
Update runtime config using environment variables
The variables prefixed with NITRO_
will be applied to runtime config, and they will override the variables defined within your nitro.config.ts
file. (matching "camelCase" version).
Example:
NITRO_HELLO_THERE="123"