How to Set Variables
- Cloudflare dashboard → project → “Settings” → “Variables and Secrets”
- “Add variable” → enter name and value → save
Reference in Code
// In Astro
const apiKey = import.meta.env.MY_API_KEY;
Local Development
Create a .env file:
MY_API_KEY=your-local-key
Add .env to .gitignore to avoid committing it.
Common Pitfalls
- After adding a variable, a redeploy is required for it to take effect
- Never commit
.envto your repository
To exclude .env from Git, see How to Set Up .gitignore. For managing secrets in GitHub Actions workflows, see Managing Secrets in GitHub Actions.
Related Posts
- Cloudflare Pages Auto-Deploy Not Working
- How to Set Up .gitignore
- Managing Secrets in GitHub Actions
- How to Deploy an Astro Site to Cloudflare Pages
Recommended Services
- Fiverr - Find freelance developers and tech experts