Caution: The Wix CLI is in Developer Preview and is subject to change.
Environment variables allow you to store configuration values and secrets outside of your code, making your applications more secure and portable. The Wix CLI uses the built-in support in Astro for environment variables, providing type-safe environment variables that can be used in backend or client-side code.
This article explains the types of environment variables available in Wix CLI projects and when to use each type.
The Wix CLI supports the following types of environment variables, each designed for specific use cases and security requirements.
| Type | Availability | Storage Location | Use case |
|---|---|---|---|
| Public client variables | Client-side and backend | .env.local file | Non-sensitive configuration that needs to be accessed in the browser (for example, API endpoints, feature flags). |
| Public server variables | Backend only | .env.local file | Non-sensitive server configuration (for example, port numbers, timeouts). |
| Secret server variables | Backend only | Wix servers | Sensitive data like API keys, database credentials, and authentication tokens. These variables are securely stored on Wix servers and must be pulled to your local environment. |
Secret server variables are designed to ensure maximum security:
wix env set command and stored securely on Wix servers, not in your local .env.local file.wix env pull command. This downloads the secret variables to your local environment temporarily..env.local file, they're never at risk of being accidentally committed to your repository.While public variables are typically stored in your .env.local file, you can also manage them using wix env set and wix env pull, similar to secret variables. This approach offers additional benefits:
.env.local files..env.local to your .gitignore and pull variables when needed, eliminating the risk of accidentally committing sensitive configuration.