What is an Environment Variable?
An environment variable is a dynamic configuration value set outside of application code that affects how software behaves at runtime. In web hosting, environment variables store sensitive data like API keys, database credentials, and configuration settings that vary between environments.
How Does Environment Variable Work?
Environment variables provide a way to configure applications without hardcoding values in source code. They are set at the operating system or container level and are accessible to running processes. Common web hosting environment variables include DATABASE_URL (database connection string), API_KEY (third-party service credentials), NODE_ENV (production or development mode), and PORT (which port the server listens on). Using environment variables keeps sensitive data out of version control and enables the same code to run with different configurations across development, staging, and production.
In modern hosting platforms, environment variables are configured through web dashboards or CLI tools. Vercel, Netlify, Heroku, and Railway all provide interfaces for managing environment variables per project and environment. For local development, .env files (loaded by tools like dotenv) provide environment variables without polluting the system environment. It is critical to never commit .env files to version control, as leaked credentials are one of the most common security incidents in software development. Many platforms also support encrypted environment variables and secrets management for additional security.