🔐
CC10045 min

Day 20

Environment Variables

Time to learn about keeping secrets safe!

Today's Lesson

Environment variables store configuration and secrets outside your code. API keys, database passwords, anything sensitive. They're different on your computer vs. the live website.

Today's Tasks

  1. 1Create a `.env.local` file
  2. 2Add a variable (not a real secret yet, just practice)
  3. 3Use it in your application
  4. 4Understand why `.env.local` is in `.gitignore`

Prompt to Use

Teach me about environment variables in Next.js. Create a .env.local file with a test variable. Show me how to use it in my app. Explain why this file shouldn't go to GitHub and verify it's in .gitignore.

Expected Outcome

Understanding of environment variables and why they matter.

New Terms

  • .env
  • .env.local
  • Environment Variable
  • NEXT_PUBLIC_
  • .gitignore

Pro Tip

`NEXT_PUBLIC_` prefix makes a variable available in the browser. Without it, the variable only exists on the server. Never put secrets in `NEXT_PUBLIC_` variables.

Coming Tomorrow

We'll review and polish your local portfolio site.

P.S. This knowledge will save you from accidentally leaking credentials.