runtimeConfig (config)
Defines server-only and public runtime values overridable by env vars.
Syntax
runtimeConfig: { ...private, public: { ...exposed } } Parameters
| Name | Type | Required | Description |
|---|---|---|---|
runtimeConfig | object | No | Root keys are server-only; the `public` sub-object is exposed to the client. Values act as defaults. |
Returns
NuxtConfig — Consumed via useRuntimeConfig() at runtime.
Examples
export default defineNuxtConfig({
runtimeConfig: {
apiSecret: '',
db: { url: '' },
public: {
apiBase: '/api',
siteUrl: 'https://example.com',
},
},
})
# .env — NUXT_ prefix overrides at runtime
NUXT_API_SECRET=prod-secret
NUXT_PUBLIC_API_BASE=https://api.example.com
Notes
Provide empty-string/placeholder defaults so the keys exist; real
values come from `NUXT_*` (private) and `NUXT_PUBLIC_*` (public)
environment variables at runtime, enabling the same build across
environments. Never put secrets under `public`.