@json-express/config-env
The default
IConfigProvidershipped with@json-express/boot.
@json-express/config-env implements IConfigProvider using the Twelve-Factor App methodology. It reads configuration exclusively from .env files and system environment variables, making it the simplest and most Docker / Kubernetes-friendly configuration strategy.
It is auto-discovered by the json-express runtime and ships as a dependency of @json-express/boot — most users never install it directly.
Installation
If you are not using @json-express/boot and want to install the runtime piece-by-piece:
npm install @json-express/config-envNaming convention
JSONExpress uses the jex namespace for every configuration key. Lowercase is preferred:
jex.port=3000
jex.auth.secret=a-strong-32-byte-secret
jex.transport=@json-express/transport-fastifyCloud platforms that forbid lowercase env vars or dotted names (Heroku, some PaaS) are supported via the uppercase double-underscore form JEX__KEY — this is the same key, just spelled differently:
JEX__AUTH__SECRET=a-strong-32-byte-secret # equivalent to jex.auth.secretIMPORTANT
The single-underscore form JEX_AUTH_SECRET is not supported — it would be ambiguous with single-word keys (JEX_PORT). The provider rejects it. Always use double underscore (__) when the dot is unavailable.
Example .env
# Server
jex.port=3000
# Logging
jex.log.level=debug
jex.log.pretty=true
# Authentication
jex.auth.secret=a-strong-32-byte-secret
jex.auth.exclude=/auth,/health
jex.auth.tokenTtl=1h
# Plugin selection (only required when multiple of the same category are installed)
jex.transport=@json-express/transport-fastify
jex.adapter=@json-express/adapter-jsonCascading precedence
The provider walks .env files in this order. Later wins, system env wins last:
.env.env.[NODE_ENV](e.g..env.development).env.local.env.[NODE_ENV].local(e.g..env.development.local)process.env— system environment variables (Docker, Kubernetes, CI)
When @json-express/config is also installed, the framework merges its own cascade on top of .env:
- Plugin defaults
jex.config.*(TypeScript / YAML / JSON)jex.config.[NODE_ENV].*.envand friends (steps 1–4 above)jex.config.[NODE_ENV].localprocess.env
The general rule: anything you can express in .env wins over anything in jex.config.* unless the file is the .local variant. Commit .env and jex.config.ts to source control with safe defaults; keep .env.local and jex.config.local.ts gitignored.
Automatic nested object construction
The provider uses buildNestedConfigFromEnv() from @json-express/core to convert flat keys into nested objects:
jex.auth.secret=abc123
jex.auth.email.from=noreply@example.comReads as:
config.get('auth.secret') // 'abc123'
config.get('auth.email.from') // 'noreply@example.com'
config.get('auth.email') // { from: 'noreply@example.com' }Both . and __ are nesting separators. Single _ stays inside the segment — jex.auth.token_ttl is { auth: { token_ttl: '1h' } }, not { auth: { token: { ttl: '1h' } } }.
Zero external dependencies
This provider depends only on dotenv. It boots in under 1 ms and adds no compile step. For richer configuration formats (YAML, TypeScript with imports, environment-specific files), install @json-express/config alongside it.
Related
- @json-express/config — advanced alternative with YAML / TypeScript support
- @json-express/boot — bundles this provider in the default stack
- @json-express/core — exposes
buildNestedConfigFromEnvand theIConfigProvidercontract