🔐
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
- 1Create a `.env.local` file
- 2Add a variable (not a real secret yet, just practice)
- 3Use it in your application
- 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.
Your Study Progress
19%
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
Day 20 of 100
Today's Tasks
0/4