

Lesson 01 · 9 min
Environment variables and secrets
The code is the same everywhere, the settings differ. Secrets never go into Git.
9 minLesson 1 of 9Practice includedAsk AI on any point
The database address, API keys, and port are configuration, and they differ between your laptop, staging, and production. They're passed as environment variables: locally from a .env file, on the server through the host's settings. In code you read process.env.DATABASE_URL.
- Check required variables at startup and fail with a clear error.
- Variables prefixed
NEXT_PUBLIC_reach the browser; secrets don't belong there. .env.exampleshows teammates which variables are needed.
Check
Lock it in before you move on
1. What do you commit to the repository?
2. A key got into Git. The first step?
3. Can a secret go into
NEXT_PUBLIC_…?