The short version
Every app needs configuration that shouldn't be hardcoded. Your database password. Your API key. Whether you're running in development or production. These values change depending on where the app is running, so they live in the environment, not in the code itself.
If you've ever seen a .env file or typed something like AIRTABLE_API_TOKEN=abc123 into a settings panel, you've worked with environment variables.
How it works
Environment variables are key-value pairs set in the system where your code runs. The app reads them when it starts up.
On your local machine, they typically live in a .env file:
DATABASE_URL=postgres://localhost:5432/myapp
API_KEY=sk-abc123
NODE_ENV=development
On a hosting platform like Vercel or Railway, you set them in a dashboard or CLI instead. The values are different for each environment: your local machine uses a test database, production uses the real one.
The critical rule: never commit .env files to Git. They contain secrets. Your .gitignore file should always exclude them. If an API key ends up in a public GitHub repo, automated bots will find it within minutes.
When you see an error like Error: Missing environment variable DATABASE_URL, it means the app tried to read a value that wasn't set. The fix is almost always adding the variable to your environment, not changing the code.
Why it matters
Environment variables are one of the first things that trip people up when deploying an app. It works on your laptop but breaks on Vercel, and the reason is almost always a missing environment variable. Understanding what they are and where they live saves hours of debugging.