How to Set Variables

  1. Cloudflare dashboard → project → “Settings” → “Variables and Secrets”
  2. “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 .env to 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.

  • Fiverr - Find freelance developers and tech experts