Glossary · Web Development

Environment Variable

en-VY-run-munt VAIR-ee-uh-bulnoun

An environment variable is a named value stored outside of code that configures how an application runs in a given environment.

Part of speech
noun
Pronunciation
en-VY-run-munt VAIR-ee-uh-bul
Origin
From 'environment,' the surrounding runtime context, and 'variable,' a named value that can change. The term comes from Unix shell conventions dating to the 1970s.

What is Environment Variable?

An environment variable is a named value stored outside of an application's code that tells the application how to behave in a particular setting. Instead of writing a database password, an API key, or a server address directly into the source code, developers reference these values by name and let the surrounding system provide them at runtime. The same code can then run in different contexts, on a developer's laptop, on a testing server, or in production, and pick up different values in each place without a single line being changed.

The mechanics are straightforward. Before an application starts, the operating system or hosting platform loads a set of key-value pairs into the process's environment. The code reads these values by their names when it needs them. For example, a variable might tell the application which database to connect to, whether to run in debug mode, or what secret token to use when calling an external service. Because the values live outside the code, they can be swapped per environment, and sensitive ones can be kept out of the shared codebase entirely, which is far safer than committing passwords into a repository where anyone with access could read them.

The concept and terminology come from Unix shell conventions dating to the 1970s, where the operating system maintained a set of named values that programs could read to learn about their surroundings. The word "environment" captures the idea of the surrounding runtime context, and "variable" reflects that these are named values which can change from one setting to another. Decades later the same mechanism underpins how modern web applications and cloud platforms are configured.

For a business, environment variables matter chiefly for security and operational flexibility. Keeping credentials and secrets out of the source code dramatically reduces the risk of a damaging leak, since a public or stolen copy of the code does not automatically expose the keys to payment systems, databases, or third-party services. They also make deployment cleaner: the same tested application can be promoted from staging to production simply by pointing it at production values, which reduces the chance of human error and supports the automated pipelines that teams rely on to ship quickly. For a website that integrates with analytics, email, and payment providers, this separation of configuration from code is essential.

The common mistakes tend to be costly. The most frequent is accidentally committing a file full of secrets into version control, which is why teams take care to exclude such files and rotate any key that slips out. Another is inconsistency between environments, where a variable set in production but forgotten in staging causes bugs that only appear after release. Overusing environment variables for values that rarely change, or scattering configuration without documentation, can also make a system confusing to operate. Environment variables relate closely to CI/CD pipelines that inject them during deployment, to authentication systems that depend on the secrets they hold, and to API endpoints and middleware that read them to know where and how to route requests. Handled with discipline, they are a quiet but fundamental part of running software safely.

Why it matters

Environment variables keep API keys and passwords out of your code and let one build run safely across development and production.