An environment variable is a named value set outside a program's code that the program reads when it runs. Developers commonly use them for settings that differ between environments, such as a database address or an API key, so the same code can run in development and in production.

It matters because it is the usual first step beyond writing a key in the code. Keeping a key in a variable, often loaded from a file such as .env, stops it being committed alongside the source and makes it easy to change.

An environment variable is not a secure vault. Other processes or users on the same machine may be able to read it, it can appear in logs, crash reports or debugging output, and it is passed on to child processes. If a .env file is committed or left in a deployed folder, the values are exposed. Variables whose names are meant to be shared with the browser, in some frameworks, end up in public code.

To reduce the risk, keep .env files out of version control, avoid printing variables in logs and use a secrets manager or workload identity for sensitive credentials where you can.