What is an environment variable?
An environment variable is a piece of configuration your app reads when it starts, kept outside the code so it can change per environment.
An environment variable is a named value that lives outside your code, in the environment your app is running in. Apps read these values at startup to find things like which database to connect to, which API key to use, and whether they are running in development or production. The same code can then behave correctly in different places by reading a different value.
The point is to keep two kinds of things out of your source code. The first is secrets, like API keys and passwords, which should never be committed to Git. The second is anything that should differ between your laptop and your production server, like a database URL.
When you set up an AI coding project, one of your first tasks is filling in a file called .env.local with the right variables. The AI tools will usually tell you which keys to set, but never paste a real secret into a public chat.
Example
# in .env.local OPENAI_API_KEY=sk-xxxxxxxxxxxx DATABASE_URL=postgres://user:pass@host/db
Related terms
Want to use Environment variable in real work?
WeCode workshops are built around AI coding tools. Pick a tier, or browse more glossary entries to get the lay of the land.
