// the apt way to handle env
Typed config,
straight from .env.
Read environment variables as real types. Zero runtime dependencies. Zod/Valibot/Arktype validation.
import { Envapter, Converters } from 'envapt';
// numbers, with a fallback
const port = Envapter.getNumber('PORT', 3000);
// ordered keys, first defined wins
const url = Envapter.get(['DATABASE_URL', 'DB_URL']);
// typed lists
const cors = Envapter.getUsing('CORS',
Converters.array({ of: Converters.String })
);// two ways to read
Two ways to read, one engine.
Read values with Envapter, or bind them to class fields with @Envapt. Both share the same parsing, converters, and cache.
import { Envapter, Converters } from 'envapt';
const config = {
port: Envapter.getNumber('PORT', 3000),
dbUrl: Envapter.getUsing('DATABASE_URL', Converters.Url)
};import { EnvNum } from 'envapt';
class Config {
@EnvNum('PORT', 3000)
declare static readonly port: number;
}A fallback removes undefined from the return type.
// converters
Every value, typed.
A converter turns the raw string into a typed value. Without one, a value stays a string.
- Converters.Numbernumber
- Converters.Booleanboolean
- Converters.Bigintbigint
- Converters.JsonJsonValue
- Converters.UrlURL
- Converters.RegexpRegExp
- Converters.DateDate
- Converters.Timenumber (ms)
- Converters.array({ of })T[]
Pass your own (raw, fallback) => T function, or validate through a Standard Schema validator (zod, valibot, arktype). All converters.
// .env, loaded
Loads your .env, not just process.env.
In production, envapt reads .env.production.local, then .env.production, then .env.local, then .env. Values from higher files win; missing files are skipped.
load order · most-specific wins
- .env.production.localwins
DATABASE_URL=pg://${DB_HOST}:5432/app - .env.production
DB_HOST=prod-db - .env.localskipped
- .envbase
resolved
Envapter.get('DATABASE_URL');
// pg://prod-db:5432/app${DB_HOST} expanded into the URL.
Node 20+ · Bun 1.3+ · Deno 2.5+ · zero dependencies
import 'envapt/config';Read environment variables as real types.
Zero runtime dependencies. Zod/Valibot/Arktype validation.