Skip to content

Nuxt Environment Variables: runtimeConfig to NUXT_

Paste a nuxt.config to get the Nuxt environment variables that override each runtimeConfig key, the type each value arrives as and the names that collide.

  • Runs in your browser

Checked

01Tool

Tool

Parsed in this tab, never run
Prefix

Nitro reads NITRO_ first, so it wins when both are set.

The variables appear here once the page has loaded.

Everything runs in this tab with acorn, which reads the code without running it. Nothing is sent or stored, and only the prefix and template settings go in the address. Names follow scule 1.3.0 and values destr 2.0.5, as in Nitro 2.13.4.

Check a variable

Paste lines from a .env file or a dashboard to see which key each one sets, and what its value arrives as.

One per line, NAME=value

The variables appear here once the page has loaded.

02Guide

How it works

How a key becomes a name

Nitro walks runtimeConfig and, for every key, joins the path to it with underscores, runs that through scule's snakeCase, upper-cases it and adds a prefix. A new word starts at a separator (-, _, . or /) and wherever a lowercase letter meets a capital. A run of capitals stays one word, except that its last capital starts the next word when a lowercase letter follows, so myAPIKey becomes MY_API_KEY.

KeyVariable
apiSecretNUXT_API_SECRET
public.apiBaseNUXT_PUBLIC_API_BASE
public.baseURLNUXT_PUBLIC_BASE_URL
oauthGitHubClientIdNUXT_OAUTH_GIT_HUB_CLIENT_ID
s3BucketNUXT_S3_BUCKET

Because separators and case changes count the same, proMax, pro-max and pro_max all become PRO_MAX. Nitro looks each name up on its own, so one variable then sets every key that shares it. Objects have names too: NUXT_PUBLIC set to a JSON object merges into the whole public block.

Why a variable is ignored

Nitro only overrides keys that exist in the built config. Declare every key you want to set, even as an empty string. Nuxt turns null and undefined into empty strings, so those count as declared.

  • A name that is off by one underscore matches nothing, and Nitro says nothing about it.
  • A default such as process.env.API_SECRET is read once, at build time. At runtime only the NUXT_ name for that key changes it.
  • nuxt dev, nuxt build and nuxt generate load .env, and nuxt preview hands it to the built server for a local check. In production the server never reads it, so set the variables where it runs.
  • In server code, useRuntimeConfig(event) applies the variables for each request. Without the event, Nitro hands back the config it worked out when the server first loaded.

app.config.ts, appConfig and most of the app block in nuxt.config are fixed at build time. Of the app options, only baseURL, buildAssetsDir and cdnURL reach runtimeConfig.app, and the Nuxt docs advise against changing buildAssetsDir at runtime.

Values arrive parsed

Nitro runs every value through destr before it touches the config, so true arrives as a boolean, 12345 as a number and {"beta":true} as an object. A value wrapped in literal double quotes stays a string with the quotes removed. In a .env file, put single quotes around those double quotes, because dotenv strips one layer of quotes itself.

What happens next depends on the key:

  • a plain key takes the parsed value, and an empty value sets it to an empty string
  • an object key merges a JSON object into itself and is replaced by anything else
  • an array is replaced whole
  • null and undefined leave the default in place

Public keys and Nuxt's own keys

Everything under runtimeConfig.public reaches the browser in the page payload, and so does runtimeConfig.app, which Nuxt uses itself. The Nuxt docs reserve top-level keys that start with app for Nuxt. Nuxt 4.6 added appSecret, a server-only root secret that modules derive their own secrets from, and you can set it with NUXT_APP_SECRET without declaring it.

On Cloudflare Workers

The Worker reads vars and secrets as environment variables under the same names. Cloudflare hands a vars value written as a JSON object to process.env as its raw JSON text, and destr parses it back, so it merges into an object key. Text values are parsed the same way, so a text var of digits arrives as a number unless it keeps the inner double quotes the Wrangler template writes.

03Questions

Questions

How does Nuxt map runtimeConfig to environment variables?
Nitro joins the path to each key with underscores, runs it through scule's snakeCase, upper-cases the result and puts NUXT_ in front. runtimeConfig.public.apiBase becomes NUXT_PUBLIC_API_BASE and apiSecret becomes NUXT_API_SECRET. A capital after a lowercase letter starts a new word, so baseURL becomes BASE_URL and oauthGitHubClientId becomes OAUTH_GIT_HUB_CLIENT_ID.
Why is my NUXT_ environment variable not working?
Usually the key is missing from runtimeConfig, and Nitro only overrides keys that exist when the app is built. Next, check the name against the table, since one misplaced underscore and Nitro ignores it without a word. Last, a built server never reads .env, and in server code useRuntimeConfig(event) is the call that applies the variables on each request.
Do I need the NUXT_PUBLIC_ prefix?
Only for keys under runtimeConfig.public, which is where the PUBLIC part of the name comes from. Those values reach the browser in every page payload, so keep secrets out of them. A server-only key is NUXT_ followed by its own name.
Why did my environment variable become a number?
Nitro parses every value with destr, so 12345 arrives as a number, true as a boolean and a JSON object as an object. To keep a value a string, put literal double quotes inside it. In a .env file that reads NUXT_MY_VAR='"12345"', and the Check a variable box above writes the line for you.
How do I set Nuxt environment variables on Cloudflare Workers?
Add secrets with npx wrangler secret put and plain settings in the vars block of your Wrangler file. The Worker sees both as environment variables. For wrangler dev, put them in .dev.vars or .env, but not both. Wrangler environments do not inherit vars, so repeat them under each one.
What is the difference between the NITRO_ and NUXT_ prefixes?
Both override the same keys. Nitro looks for the NITRO_ name first and falls back to NUXT_, the prefix Nuxt configures, so when both are set the NITRO_ one wins. In a Nuxt app, use NUXT_, which is what the Nuxt docs use throughout.

04Sources

Sources

Nuxter

Building a SaaS on Nuxt?

Nuxter declares every key it reads in runtimeConfig, down to an empty slot for each price and AI model, so each NUXT_ variable it documents overrides something. Its build refuses plan, AI role and provider ids that scule would collapse onto another key's variable.

See what Nuxter includesFrom $249, one-time.