By the end of this lesson your previews will run on test data and your live site on live data, each with its own environment variables, and you will know exactly when a change needs a redeploy.
You need: the branch-and-preview habit from Lesson 1, a .env.example file (Keep secrets secret), access to your Vercel project's settings, your coding agent · Time: 8 minutes
An environment variable is a setting your code reads by name, like
NEXT_PUBLIC_SUPABASE_URL, instead of having the value written inside the code. You already keep secrets this way. Now the twist: the same name can have a different value in each environment.Vercel has three:
- Development: your laptop. Values come from your
.env.localfile. - Preview: every preview deployment from Lesson 1.
- Production: the live site from
main.
For the Sharma Coaching fee tracker, make two Supabase projects:
feetracker-testwith fake students, andfeetracker-livewith the real ones. Development and Preview point at test; only Production points at live.Same names everywhere. Only Production gets live values. Why?If previews used the live database, testing a "delete student" button would delete a real student. Separate values make previews safe to break.
- Development: your laptop. Values come from your
Log in free to read the rest of this lesson
Every lesson is free. A free account unlocks all of them and saves your progress.
Still to come in this lesson:
- Write an environment sheet first
- Add the values in Vercel, per environment
- Public prefixes are baked in at build time
- Changed a value? Redeploy
- Recap