Syntax
Ternary Conditions
Use ternary expressions to add conditional logic in your `.envx` files.
Ternary Expressions
Ternary expressions enable you to include simple conditional logic directly inside your .envx configuration. This lets you define environment variables that change their value based on other variables or flags, making your configuration more dynamic and flexible.
NODE_ENV = "production"
API_URL = ${NODE_ENV} == "production" ? "https://api.prod.com" : "http://localhost:3000"In this example, API_URL will be set to the production API URL only if NODE_ENV equals "production". Otherwise, it falls back to the local development URL.
Supported Syntax
- Equality checks:
==,!= - Boolean values (
true,false) - String literals in conditions and results
Practical Example
DEV_MODE = true
NODE_ENV = "development"
PROD_DEBUG_ENDPOINT = "http://api.example.com/debug"
DEBUG_ENDPOINT = ${DEV_MODE} ? "http://localhost:1234/debug" : "${PROD_DEBUG_ENDPOINT}"
LOG_LEVEL = ${NODE_ENV} == "development" ? "debug" : "info"Here:
DEBUG_ENDPOINTis set only ifDEV_MODEis true.LOG_LEVELswitches between"debug"and"info"based onNODE_ENV.
Notes
- Conditions are simple and meant for straightforward toggles.
- Complex logic should be handled outside
.envx(e.g., in your application code). - Make sure variables used in conditions are declared beforehand for clarity and correctness.
Ternary expressions make
.envxfiles powerful yet readable, enabling environment-specific values without duplicating entire configs.