Environment Variables
Set environment variables that are available during the build process and at runtime.
Adding environment variables
- Go to your site's Settings tab
- Under Environment Variables, click Add Variable
- Enter the key and value
- Click Save
Usage
Environment variables are injected during the build process. Access them the same way you normally would in your framework:
Next.js
// Only variables prefixed with NEXT_PUBLIC_ are available in the browser
const apiUrl = process.env.NEXT_PUBLIC_API_URL
Vite (React, Vue, Svelte)
// Only variables prefixed with VITE_ are available in the browser
const apiUrl = import.meta.env.VITE_API_URL
Astro
const apiUrl = import.meta.env.PUBLIC_API_URL
caution
Never store secrets (API keys, passwords) in client-side environment variables. Variables prefixed with NEXT_PUBLIC_, VITE_, etc. are embedded in your built JavaScript and visible to anyone.
Built-in variables
WebStadia automatically provides these variables during builds:
| Variable | Description |
|---|---|
WEBSTADIA | Always true — detect if running on WebStadia |
NODE_VERSION | Node.js version used for the build |