JSPM

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

Type-safe environment variables for TypeScript. Zero-dependency .env loader and parser with one API across Node, Bun, Deno, Cloudflare Workers, and the Browser. Decorators, converters, Standard Schema (zod/valibot/arktype) validation, and much more.

Package Exports

  • envapt
  • envapt/browser
  • envapt/config
  • envapt/workerd

Readme

envapt logo

envapt

The apt way to handle environment variables.
Read them as typed values, with zero runtime dependencies.

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. On Node, Bun, and Deno it reads process.env and your .env files; on Cloudflare Workers and in the browser you bind the source with Envapter.useSource(...).

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.
  • Runs on Node, Bun, Deno, Cloudflare Workers, and the browser. Node >=20, Bun >=1.3, Deno >=2.5 (ESM and CJS); the Workers and browser builds resolve through the package exports conditions.
  • .env loading on Node, Bun, and Deno. A per-environment file cascade, ${VAR} templates, and strict / required checks. Off Node there is no filesystem, so you bind a source with Envapter.useSource(...) and read with the same typed API.

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 from any call site, in JavaScript or TypeScript. No build step. On Node the source is bound for you; on Workers and in the browser, call Envapter.useSource(...) first.

import { Envapter, Converters } from 'envapt';

const port = Envapter.getNumber('PORT', 3000);
const origins = Envapter.getUsing('ALLOWED_ORIGINS', Converters.array(), []);

On Cloudflare Workers, env is importable at module scope, so bind it once in a config module; in the browser, seed a ManualEnvSource from the object your bundler injects.

import { env } from 'cloudflare:workers';
import { Envapter, WorkerEnvSource } from 'envapt';

Envapter.useSource(new WorkerEnvSource(env));

export const apiToken = Envapter.get('API_TOKEN');

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