# Global variables (Env)

Define project-wide values in Project Settings and read them through Env.

URL: https://webrad.atentor.com/docs/global-variables
Updated: 2026-11-07

Project Settings exposes environment variables through the read-only global `Env`. Each variable has separate **Development** and **Production** string values.

## Create a variable

1. Open **Project Settings** in the Project panel.
2. Select **Environment variables**.
3. Under **Environment used for Preview and Build**, choose **Development**.
4. Click **Add variable**, enter `API_BASE_URL`, and set its value to `https://dev-api.example.com`.
5. Switch the environment to **Production** and set the same variable to `https://api.example.com`. Switching environments changes which value is being edited; it keeps the other value.
6. Select the environment you want for Preview, then click **Apply changes**.
7. Save the project with **Ctrl+S**. Run Preview again to compile the selected values.

Names are unique and case-sensitive. Start with an uppercase letter and use uppercase letters, numbers, and underscores. For example, `API_BASE_URL` is valid; `api-url` is not. Use the remove action on the variable row to delete it, then apply and save.

## Read values in code

Add an API Client named **ApiClient1**. In a page event, use the configured value:

```ts
const apiUrl = Env.API_BASE_URL;
ApiClient1.Connection.BaseURL = apiUrl;
Message(apiUrl);
```

Use `Env.API_BASE_URL` directly, without an import or `this`. Monaco suggests configured names and reports undeclared names. Env is read-only at runtime; edit the value in Project Settings and compile again to change the distributed setting.

## Numbers and booleans

All values remain strings, including `"25"` and `"false"`. Add `PAGE_SIZE` and `ENABLE_REPORTS` in Project Settings before using this example:

```ts
const pageSize = Number(Env.PAGE_SIZE);
if (!Number.isInteger(pageSize) || pageSize < 1) {
  throw new Error('PAGE_SIZE must be a positive integer.');
}
const reportsEnabled = Env.ENABLE_REPORTS === 'true';
console.log(pageSize, reportsEnabled);
```

Choose an explicit convention such as `true`/`false`. JavaScript treats every nonempty string, including `"false"`, as truthy.

## Preview and exported applications

| Where the application runs | Value selection |
| --- | --- |
| Preview in the IDE | Environment variables → Environment used for Preview and Build. |
| Web/PWA export | Build and publishing → Deploy environment. |
| Native export | Build and publishing → Deploy environment. |

The compiler includes the selected values in the application. Changing Project Settings after export requires a new export. They are visible in distributed JavaScript: use public URLs and feature settings here, and keep server credentials on the backend.

## Other kinds of state

For a value that changes during use, declare a typed field on the page or reusable class. That field belongs to the instance. Use a shared Unit when several parts of the application need the same function; see [Global functions](https://webrad.atentor.com/docs/globals). Env remains the configuration source for values selected before execution.

See [Project settings](https://webrad.atentor.com/docs/configuracoes-do-projeto) for the other sections and [Packages and libraries](https://webrad.atentor.com/docs/packages) for installing dependencies.
