Manage Environment Variables

Caution: The Wix CLI is in Developer Preview and is subject to change.

Configure and use environment variables in your Wix CLI project to store configuration values and secrets outside of your code. Learn about the types of environment variables available in Wix CLI projects.

Step 1 | Define the schema

In this step, you define the structure of your environment variables in astro.config.mjs, specifying each variable’s type, context (client or server), and access level (public or secret) before assigning actual values.

Copy

Read more about the schema definition in the Astro documentation.

Step 2 | Configure environment variables

In this step, you configure public or secret variables.

Configure public client variables

To configure public variables:

  1. Add your variables to the .env.local file in your project root.
Copy
  1. Use the wix env set command to set the variables.
Copy

Important: Don't edit any of the WIX_CLIENT variables in the .env.local file. The Wix CLI manages these variables.

Configure secret server variables

To configure secret server variables:

  1. Use the wix env set command to set the secret variable.
Copy
  1. Pull the secret variables to your development environment using the wix env pull command.
Copy

Note: You must run wix env pull after setting secret variables. Without running wix env pull, the wix dev command doesn't work.

Step 3 | Use environment variables in your code

In this step, you learn how to import and use environment variables.

Use client variables

Import public client variables from astro:env/client. The following example imports and uses the API_URL variable.

Copy

Use backend variables

Import public server and secret variables from astro:env/server:

Copy

Step 4 | Build and release your project

After setting your environment variables, build and release your project to apply the changes.

To build and release:

  1. Build your project.
Copy
  1. Release your project to apply the changes.
Copy

See also

Did this help?