Global variables (Env)
Project Settings exposes environment variables through the read-only global Env. Each variable has separate Development and Production string values.
Create a variable
- Open Project Settings in the Project panel.
- Select Environment variables.
- Under Environment used for Preview and Build, choose Development.
- Click Add variable, enter
API_BASE_URL, and set its value tohttps://dev-api.example.com. - 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. - Select the environment you want for Preview, then click Apply changes.
- 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:
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:
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. Env remains the configuration source for values selected before execution.
See Project settings for the other sections and Packages and libraries for installing dependencies.