JSPM

  • Created
  • Published
  • Downloads 1154
  • Score
    100M100P100Q106381F
  • License Apache-2.0

Type-safe environment variables for TypeScript. Zero-dependency .env loader and parser with the same API on Node, Bun, and Deno. Decorators, converters, and Standard Schema (zod/valibot/arktype) validation.

Package Exports

  • envapt
  • envapt/config

Readme

envapt logo

envapt

The apt way to handle environment variables.
Read them as typed values, with zero runtime dependencies and the same API on Node, Bun, and Deno.

npm downloads jsr CI License


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 | undefined

Read the docs →

What you get

  • Typed values. A fallback removes undefined from 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 .env parser, 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.
  • .env loading 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/envapt

Quick 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/envapt

Built by @materwelonDhruv · Apache 2.0