Environment variables, explained
Code often needs a secret, such as a CMS token. Writing it in the code would put it in Git history, where it can be copied. An environment variable keeps it in the host's settings instead.
They also let the same code behave differently per environment. A preview build can point at a test dataset, while production points at the live one.
Be careful what reaches the browser. In Astro, variables starting with PUBLIC_ are included in code the browser can read, and Next.js does the same with NEXT_PUBLIC_. Secrets must never use those prefixes.
Locally, these values usually live in a .env file that Git ignores. If a key does leak, rotate it straight away, because deleting it from the code does not remove it from history.



