How to understand configuration and environment variables in a codebase
Find every setting an app depends on: env files, config modules, build-time versus runtime variables, secrets, defaults and what differs between environments.
Configuration decides which database an app talks to, which features are on and which external services it calls. Two copies of the same code with different configuration can behave completely differently, which is why "works on my machine" is so often a config problem.
Find where configuration enters
.envfiles and examples like.env.exampleor.env.local.example- A config module, often
config.tsorsrc/config/, that reads variables and exports typed settings - Framework config:
next.config.ts,nuxt.config.ts,vite.config.ts,astro.config.mjs - Platform settings: environment variables set in Vercel, AWS, Cloudflare or Kubernetes, which aren't in the repository at all
- Config files: JSON, YAML or TOML in the repository
List every variable
Search for process.env., import.meta.env., Deno.env.get and the framework's own helpers. Build a list:
| Variable | Used in | Required | Default | Secret |
|---|---|---|---|---|
| DATABASE_URL | db/client.ts:4 | Yes | none | Yes |
| NEXT_PUBLIC_SITE_URL | lib/site.ts:8 | No | http://localhost:3000 | No |
Compare it with .env.example. Missing entries in the example are a common onboarding trap.
Separate build-time from runtime
Some variables are baked into the bundle when the app is built; changing them later has no effect until a rebuild:
- Next.js
NEXT_PUBLIC_*, ViteVITE_*, Create React AppREACT_APP_*: inlined into client code at build time, and public. - Server-side variables read at runtime can change between deploys without rebuilding, depending on the platform.
Knowing which is which explains many deploy surprises.
Know which are public
Anything sent to the browser is public, whatever it's called. Check that no secret is read in client code. A variable prefixed for the client and containing a key is a security bug.
Check validation and defaults
Good codebases validate configuration at startup, often with a schema library, and fail fast with a clear message. Others use defaults silently, so a missing variable produces strange behaviour instead of an error. Note which kind yours is.
Compare environments
Make a table of how development, staging and production differ: database, API keys (test or live), feature flags, log levels. Many "only in production" bugs come from a setting that differs.
Ask about configuration
Ask RepoGrasp "which environment variables does this app read, where, and which are exposed to the browser?" It searches source files and cites each read. RepoGrasp deliberately skips .env files, so it sees how variables are used, never their values, which is how it should be.