Docker and deployment

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.

.env and .env.example
AI

You can ask about this rule«A secret in Git is already a leaked secret»

  • Check required variables at startup and fail with a clear error.
  • Variables prefixed NEXT_PUBLIC_ reach the browser; secrets don't belong there.
  • .env.example shows teammates which variables are needed.
AI

You can ask about this point«Lesson summary»

Check

Lock it in before you move on

  1. 1. What do you commit to the repository?

  2. 2. A key got into Git. The first step?

  3. 3. Can a secret go into NEXT_PUBLIC_…?

PracticeSolve the lesson tasksA few short tasks in the editor. Check your code right away and see where it goes wrong.Start practice