Environment variable
- Standard term
An environment variable is a named setting stored outside your code that your app reads when it runs. It commonly holds secret keys and settings that differ between the computers the app runs on.
The code names the setting, such as EMAIL_KEY, and the computer running it supplies the value. Your laptop can hold a test key and the server the live one, so the same code runs everywhere, and the key stays out of shared files and their history.
Where you’ll meet it
An email arrives from the site that hosts your project's code. It found a secret key for your email-sending service in one of your files, and the project is public. Weeks ago, you set up reminder emails by copying the email service's quick-start example, which had the key written straight into the code.
What to do
- In the email service's dashboard, create a new key and delete the leaked one.
- Add the new key in your hosting platform's environment variable settings, named EMAIL_KEY.
- Ask your agent to make the code read EMAIL_KEY and remove the old key.
Easy to mix up
Encryption keeps data unreadable to anyone without the key. An environment variable has no such lock: the app, and anyone with access to the server, can read it as is.
Check yourself
You change SUPPORT_EMAIL in your hosting platform's settings to a new address. For three days the contact form keeps using the old one. Then you publish a small spelling fix, and from that moment the form uses the new address. What explains the delay?
Go deeperA key can travel further than the app that needed it
On Linux, macOS, and Windows, every running program, or process, starts with a set of named values from whatever launched it, and any program it starts gets a copy. That inheritance is how a hosting platform hands your app its settings. It is also how a key can reach a script or tool that never needed it.
Values also leak through debug output, crash reports, and logs. In web apps, a common slip is building a variable's value into the code sent to visitors' browsers, where anyone can read it; Next.js marks those with the prefix NEXT_PUBLIC_. Larger teams keep keys in a secret store that hands them to the app and replaces them on a schedule.