Syntax Reference
Comprehensive and developer-friendly reference for the .envx configuration syntax types, interpolation, validation, and schema.
.envx Syntax Reference
The .envx format is a typed, validated, and expressive environment configuration syntax designed as a modern replacement for legacy flat .env files. It enhances clarity, reduces runtime errors, and enables powerful editor tooling.
Key Concepts
- Typed values: Variables have explicit types such as
string,number,boolean,enum,url, oremail. - Interpolation: Embed other variables dynamically using
${VAR_NAME}syntax. - Conditional expressions (ternary): Inline logic to assign different values based on conditions.
- Schema section: Metadata and validation rules for variables, defined at the file’s end.
Variable Assignments
Variables are assigned as:
KEY=VALUESupported Value Types
- Strings: Quoted or unquoted text.
- Numbers: Numeric literals.
- Booleans:
trueorfalse. - Multiline strings: Triple quotes
"""enclose multi-line text. - Expressions: Interpolations and ternary operators for dynamic values.
Interpolation
Interpolation lets you embed the value of one variable inside another, using the syntax:
API_URL=${BASE_URL}/apiHere, ${BASE_URL} will be replaced with the value of the BASE_URL variable at runtime.
💡 Tip: Variables referenced in interpolation must be defined earlier or in the same scope.
Conditional (Ternary) Expressions
You can use inline ternary operators to assign values based on a condition:
DEV_MODE=${NODE_ENV} == "development" ? true : falseExplanation:
${NODE_ENV}is interpolated to get the current environment value.- The expression checks if
NODE_ENVequals"development". - If true,
DEV_MODEbecomestrue. - Otherwise,
DEV_MODEis set tofalse.
This allows dynamic config based on environment:
API_URL=${DEV_MODE} ? "http://localhost:3000" : "https://api.example.com"Schema Definition
At the bottom of the file, you define schema blocks that describe and validate variables:
[VARIABLE_NAME]
type = "string"
required = true
default = "defaultValue"
description = """Detailed documentation."""
values = ["allowed", "enum", "values"]
deprecated = false⚠️ Important:
- Schema sections must be after all variable assignments.
- You cannot declare variables inside schema blocks.
valuesis only valid iftype="enum".
Supported Schema Properties
| Property | Type | Description |
|---|---|---|
type | string | Data type. Allowed: string, number, boolean, enum, url, email. |
required | boolean | If true, the variable must be set or have a default. |
deprecated | boolean | Marks variable as deprecated; tooling may warn when used. |
description | string | Documentation shown in editor hover, supports multiline triple quotes. |
default | any | Default value if none is assigned. |
values | array[string] | Valid only with enum type; lists permitted string values. |
Property Details
type
Specifies the data type. Examples:
string: Arbitrary textnumber: Numeric valueboolean:trueorfalseenum: One of thevaluesarrayurl: Valid URL formatemail: Valid email format
Example:
[NODE_ENV]
type = "enum"
values = ["production", "development", "test"]
default = "development"
required = truerequired
If true, the variable must be assigned or have a default, otherwise validation fails.
deprecated
Flags variables as obsolete. Useful to warn teams of upcoming removals.
description
Rich, multiline documentation for developer clarity and editor tooltips.
default
Fallback value if none assigned.
values
An array of allowed values, only valid with enum type.
Full Example
# Variable assignments
DEV_MODE=${NODE_ENV} == "development" ? true : false
PORT=8080
API_URL=${DEV_MODE} ? "http://localhost:${PORT}" : "https://api.example.com"
API_ENDPOINT="${DEV_MODE}/v1"
GREETING="Hello "user"!"
MULTILINE_EXAMPLE="""
I am .ENVX the best .env alternative!
"""
# Schema definitions (must be last)
[DEV_MODE]
type = "boolean"
[API_URL]
type = "url"
description = """Base URL for the API."""
[PORT]
type = "number"
required = true
description = "Port number the server listens on."
[GREETING]
type = "string"
description = """Welcome message displayed to users."""
[NODE_ENV]
type = "enum"
values = ["production", "development", "test"]
default = "development"
required = true
[ANY_ARG2]
type = "string"
default = "any value"
required = trueImportant Notes 🛠️
- Schema blocks must always appear after all variable assignments.
- Variables cannot be declared inside schema blocks.
- The
valuesproperty applies only toenumtypes. descriptionproperties improve editor support and docs but do not affect runtime.deprecatedflags help maintain backward compatibility and notify users.
This syntax empowers you to manage environment variables with strict typing, live validation, and rich editor support making your configs safer, clearer, and easier to maintain.