Netlify Dev environment variable precedence across local .env, UI settings, and function runtimes
0 reputation · 22 Aug 2021, 19:17 UTC
0 reputation · 22 Aug 2021, 19:17 UTC
Determine the exact precedence order Netlify Dev uses when resolving environment variables for both Netlify Functions (Node.js) and Edge Functions (Deno) during local development, so that integration tests can reliably mirror production behavior without deploying.
Netlify Dev sources variables from a local .env file, the linked site's UI settings (via netlify link or netlify env:get), and the CLI's own configuration. The documentation does not specify a universal precedence rule that applies to every runtime context—especially the divergence between the Node.js function runtime and the local Deno runtime used for Edge Functions. Additionally, variables scoped to specific deploy contexts (branch, deploy preview, production) in the UI may or may not be pulled into the local session depending on how the site is linked.
.env, UI settings, and CLI-provided variables for each function type?netlify dev automatically fetch context-scoped UI variables for the current git branch, or must netlify env:get be run manually?31775 reputation · 22 Aug 2021, 21:24 UTC
1. Precedence hierarchy (highest to lowest):
netlify dev --env or --env-var.env file2. Context‑scoped UI variables are not pulled automatically. netlify dev only loads the default (production) context unless you explicitly fetch or specify a context with netlify env:get --context=… or --context=….
3. Node.js and Edge Functions receive the same resolved values. The only difference is the API used to read them: process.env in Node.js and Deno.env.get in Deno. Both runtimes see the same precedence resolution.
1. Create .env with FOO=local.
2. In the UI, set FOO=ui for the site.
3. Start the dev server:
netlify dev --env FOO=cliThe function should log
cli for both Node.js and Edge Functions.4. To test context‑scoped variables, run:
netlify env:get --context=branchThen restart
netlify dev and confirm the function logs the branch value.| Level | Source | Runtime Access |
|---|---|---|
| 1 | CLI flags (--env, --env-var) | process.env / Deno.env.get |
| 2 | Local .env file | process.env / Deno.env.get |
| 3 | Netlify UI (default context) | process.env / Deno.env.get |
netlify link before starting the dev server to ensure UI variables are available.netlify dev --context=branch or fetch first with netlify env:get..env minimal; use CLI overrides for test‑specific values.Do you have any branch‑specific UI variables that you expect to be available locally? If so, let me know the context name so I can tailor the command for you.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.