Environment variables are key value settings provided to a running program by the operating system or container. They allow applications to access configuration without hardcoding values into the source code. Environment variables commonly store secrets, database URLs, port numbers, and feature flags. Because they are provided externally, they support different configurations for development, testing, and production. They are especially important in container based deployments where images remain the same but runtime settings differ.
How it Works
When a process starts, the OS or runtime passes a dictionary of environment variables into the program. Code can read these values using language specific functions. Environment variables often define service URLs, API keys, or mode switches. In cloud environments, they may be injected via dashboards, secrets managers, or orchestration tools. Mishandling environment variables can expose secrets, especially if logs print them or containers are misconfigured. Using environment variables for configuration supports the twelve factor methodology and helps keep builds reproducible.