Environment Variables
Definition
Dynamic values that affect the way running processes will behave on a computer. They are heavily used to store sensitive information and configuration data outside of the application's source code.
Explain Like I'm New
Imagine building a robot that connects to a database. You don't want to weld the database password permanently into the robot's brain (source code), because if you want to sell the robot to someone else, they can't change the password. Instead, you put a sticky note on the robot's back. When the robot turns on, it reads the sticky note (Environment Variable) to know the password.
Real World Example
Using a `.env` file to store `DATABASE_URL`, `STRIPE_SECRET_KEY`, and `NODE_ENV`. The `.env` file is heavily excluded from Git via `.gitignore` so secrets never leak to GitHub.
Common Use Cases
- •Security
- •Configuring dev/staging/prod environments
Interactive Example
Interview Questions
basic
- What object in Node.js contains the environment variables?
intermediate
- Why do you need the `dotenv` package?