Package Exports
- envapt
- envapt/config
Readme
|
envapt
The apt way to handle environment variables. |
process.env always hands you a string | undefined. envapt returns the type you asked for, with a
fallback that removes undefined from the return type.
import { Envapter } from 'envapt';
const port = Envapter.getNumber('PORT', 3000); // number, not string | undefinedWhat you get
- Typed values. A fallback removes
undefinedfrom the return type. Built-in converters cover numbers, booleans, bigint, JSON, URLs, regular expressions, dates, durations, and arrays, or pass your own function or a Standard Schema validator (zod, valibot, arktype). - Zero runtime dependencies. envapt ships its own
.envparser, so nothing is added to your dependency tree. - The same API on Node, Bun, and Deno. Node
>=20, Bun>=1.3, Deno>=2.5; ESM and CJS. .envloading built in. A per-environment file cascade,${VAR}templates, and strict / required checks.
Install
npm install envapt
pnpm add envapt
yarn add envapt
bun add envapt
deno add jsr:@materwelon/envaptQuick start
Read values functionally with Envapter, or bind them to class fields with the @Envapt decorator.
Both share the same parsing, converters, and cache.
Functional
Read a value anywhere, in JavaScript or TypeScript. No build step.
import { Envapter, Converters } from 'envapt';
const port = Envapter.getNumber('PORT', 3000);
const origins = Envapter.getUsing('ALLOWED_ORIGINS', Converters.array(), []);Decorator
Bind a value to a class field. TypeScript, with experimentalDecorators in your tsconfig.json.
import { Envapt, Converters } from 'envapt';
class Config {
@Envapt('PORT', { converter: Converters.Number, fallback: 3000 })
declare static readonly port: number;
}Documentation
The guide, converter reference, validation, configuration, and the v4 to v5 migration live at envapt.materwelon.dev.
Agent skill
Install the envapt agent skill so AI coding tools use the correct API:
npx skills add materwelonDhruv/envaptBuilt by @materwelonDhruv · Apache 2.0