Environment VariablesAdvanced
1Question 1 of 1
bashHow does Next.js handle environment variables and public exposure?
Explanation & Concept
By default, environment variables in `.env` are private and accessible **only on the server** (Node.js runtime).
To expose a variable to the browser/client-side code, it must be prefixed with `NEXT_PUBLIC_`.
Code Example
bash
# .env.local
DATABASE_URL="postgres://admin:secret@localhost:5432/app" # PRIVATE: Server only!
NEXT_PUBLIC_API_URL="https://api.production.com" # PUBLIC: Exposed to client JS!How It Works & Key Takeaways
The `NEXT_PUBLIC_` prefix prevents accidentally leaking database credentials and secret API keys to the browser bundle.
Mock Test · 1 Questions · Optional
Ready for Route Handlers?
Take a quick test to evaluate yourself, or move straight to the next module.
Advanced1 questions