What Environment variables means
Keeping secrets in environment variables instead of code means they are not exposed in your repository. Hosts like Netlify and Vercel let you set different values for production and previews.
Why it matters for your website
Keeping API keys and passwords out of your code protects them if the code is shared or leaked. Environment variables also let the same code use test settings on a preview and live settings in production. A leaked key can lead to stolen data or surprise bills from misused services.
A boutique's site uses an environment variable for its payment API key. Developers can share the code on GitHub without exposing the key, and previews use a test key instead.
Tips
- Never commit files like .env to your code repository.
- Use separate keys for testing and live sites.
- Rotate any key right away if it was ever exposed.
Common mistakes
- Marking a secret as public so it ends up visible in the browser's JavaScript.
- Sharing keys over email or chat instead of a password manager.
