App Development Vocabulary — Day 26: Environment Variable
An environment variable is a name and a value that live in the environment (Day 25), outside the code.
Two jobs.
Config that differs per environment: DATABASE_URL, the API base URL, whether debug output is on.
Secrets that must never be in the repository: API keys, passwords, signing tokens.
The code reads them by name. In Node it's process.env.DATABASE_URL, in Python it's os.environ["DATABASE_URL"]. Same code, different value depending on where it runs.
Locally, a .env file holds them, and .gitignore keeps that file out of commits. Push an API key to a public GitHub repository and bots scanning for exactly that will find it fast.
Quick check: Where should your Stripe secret key live: in the code, or in an environment variable?
## SPOKEN LINES
  • You push the code and the real database password goes to GitHub with it. Now it sits in the history for anyone to read.
  • - ENVIRONMENT VARIABLE
  • - An environment variable is a named value the operating system hands to the program when it starts. The code reads the name and gets whatever value that environment set.
  • - A variable called database URL points at your laptop in development and the database in production, stripe key holds the payment secret, and port says which number to listen on.
  • - So an environment variable is a setting kept outside the code and read in at startup. Tomorrow: Localhost, the address your own computer uses for itself.
## NEXT
Day 27: Localhost
0
0 comments
Joshua Payne
4
App Development Vocabulary — Day 26: Environment Variable
CMD & Conquer
skool.com/cmdandconquer
CMD & Conquer helps designers, filmmakers, photographers, developers, and business owners build an office of agents around their work.
Powered by