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})
export default defineNuxtConfig({  nitro: {    // Nitro options  }})

Read all the available options to configure Nitro.

Nitro loads the configuration using unjs/c12, giving more possibilities such as using .nitrorc.


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.


export default defineNitroConfig({  runtimeConfig: {    helloThere: "foobar",  }})
export default defineNuxtConfig({  runtimeConfig: {    helloThere: "foobar",  }})

You can now access the runtime config using useRuntimeConfig(event).


api/example.get.ts (nitro)
export default defineEventHandler((event) => {  return useRuntimeConfig(event).helloThere // foobar});
server/api/example.get.ts (nuxt)
export default defineEventHandler((event) => {  return useRuntimeConfig(event).helloThere // foobar});
Note: Consider using 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:


You can universally access environment variables using import.meta.env.TEST or process.env.TEST.

Note: Consider writing any logic that depends on environment variables within event handlers and utilities and avoid accessing and caching them in ambient global contexts.

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).


.env (nitro)
.env (nuxt)