🚀 The .envx File Format & dotenvx Library

Dotenvx

dotenvx is a modern, type-safe alternative to .env files — with validation, smart interpolation, enums, defaults, CLI support, and VSCode integration. Configuration and schema live together in a single .envx file.

npm install dotenvxjs
Get Started
.envxExample .envx
1# .envx - Modern environment configuration
2DEV_MODE=false
3
4# Smart interpolation with ternary expressions
5API_URL=${DEV_MODE} ? "http://localhost:3000" : "https://api.example.com"
6API_TOKEN=${DEV_MODE} ? "dev-token" : "prod-token"
7
8# Multiline strings with triple quotes
9DATABASE_CONFIG="""
10{
11  "host": "localhost",
12  "port": 5432,
13  "ssl": true
14}
15"""
16
17# Schema definition for type safety
18[DEV_MODE]
19type="boolean"
20description="Development mode flag"
21
22[API_URL]
23type="url"
24required=true
25description="Main API endpoint"

Why .envx Format?

.envx is an enhanced environment configuration format with validation, interpolation, and schema support

.envx File Format
Type-safe, expressive config format with schema, validation, and dynamic logic support.
# .envx example
API_URL=${DEV} ? "localhost" : "prod.com"

[API_URL]
type="url"
required=true
dotenvx Library
TypeScript library to read .envx files with full schema validation and type safety.
import { loadEnvx, getEnvx, getEnv } from 'dotenvxjs'
import { Envx } from './envx.ts'

loadEnvx() // Loads and validates .envx files during development

const env = getEnvx<Envx>() // Use in dev or when .envx is available

// For production:
// 1) Run `npx dotenvx generate` to create a standard .env file and .envx.meta.json schema
// 2) Use getEnv() to read from .env with type safety (no runtime validation)
const prodEnv = getEnv<Envx>()
Schema Validation
Define types, constraints, and validation rules inside your .envx file.
[PORT]
type="number"
deprecated=true
required=true
Variable Interpolation
Use other variables and ternary expressions for dynamic environment values.
BASE_URL="https://api.com"
API_URL="${BASE_URL}/v1"
KEY=${DEV} ? "dev-key" : "prod-key"
Powerful CLI
Tools for validation, type generation, and converting .envx to .env files.
npx dotenvx check
npx dotenvx types
npx dotenvx build
npx dotenvx generate
npx dotenvx watch
TypeScript Integration
Auto-generates TypeScript types from your .envx schema for type-safe access.
// Auto-generated types
// > npx dotenvx types
import { Envx } from "./envx.ts";
import { getEnvx, getEnv } from "dotenvxjs";

const envDev = getEnvx<Envx>()  // Development: full validation and .envx support
const port: number = envDev.PORT
const url: string = envDev.API_URL

const envProd = getEnv<Envx>()  // Production: reads .env with type safety via .envx.meta.json

.envx vs Traditional .env

See what makes .envx the modern choice for environment configuration.

📄Traditional .env Files
Simple key=value pairs only
No type information
No validation or schema
No variable interpolation
No conditional values
No multiline support
Manual type conversion needed
Modern Format
.envx Files
Rich syntax with schema definitions
Built-in type system
Schema validation & constraints
Variable interpolation with ${VAR}
Ternary expressions for conditions
Multiline strings with triple quotes
Automatic type conversion & safety

Ready to Upgrade Your Environment Config?

Join developers who have already switched to dotenvx for better type safety, validation, and developer experience.