About Environment Variables

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.

Types of environment variables

The Wix CLI supports the following types of environment variables, each designed for specific use cases and security requirements.

TypeAvailabilityStorage LocationUse case
Public client variablesClient-side and backend.env.local fileNon-sensitive configuration that needs to be accessed in the browser (for example, API endpoints, feature flags).
Public server variablesBackend only.env.local fileNon-sensitive server configuration (for example, port numbers, timeouts).
Secret server variablesBackend onlyWix serversSensitive 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

Secret server variables are designed to ensure maximum security:

  • Secret variables are set using the wix env set command and stored securely on Wix servers, not in your local .env.local file.
  • To run your project locally with secret variables, you must pull them from Wix servers using the wix env pull command. This downloads the secret variables to your local environment temporarily.
  • Since secret variables aren't stored in your .env.local file, they're never at risk of being accidentally committed to your repository.

Public variables on Wix servers

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:

  • Store all environment variables on Wix servers instead of tracking them locally.
  • Team members can sync variables without sharing .env.local files.
  • Add .env.local to your .gitignore and pull variables when needed, eliminating the risk of accidentally committing sensitive configuration.

See also

Did this help?