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 dotenvxjs1# .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".envx is an enhanced environment configuration format with validation, interpolation, and schema support
# .envx example
API_URL=${DEV} ? "localhost" : "prod.com"
[API_URL]
type="url"
required=trueimport { 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>()[PORT]
type="number"
deprecated=true
required=trueBASE_URL="https://api.com"
API_URL="${BASE_URL}/v1"
KEY=${DEV} ? "dev-key" : "prod-key"npx dotenvx check
npx dotenvx types
npx dotenvx build
npx dotenvx generate
npx dotenvx watch// 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.jsonSee what makes .envx the modern choice for environment configuration.
Join developers who have already switched to dotenvx for better type safety, validation, and developer experience.