v8.1.0

Introduction

Read config as typed values from any source, with zero runtime dependencies and zod/valibot/arktype validation.

envapt reads config as typed values from any source you bind, process.env, a Cloudflare Workers binding, a browser bundle, a secret store, or any object. You give it a key and a fallback, and it returns a number, boolean, URL, Date, an array, or any type you define, instead of the string | undefined you get raw.

const redisUrl = .('REDIS_URL', ., new ('redis://localhost:6379'));
const redisUrl: URL

Two ways to read

Read values functionally with Envapter, or bind them to class fields with the @Envapt decorator. Both share the same parsing, converters, and cache.

class  {
    @('REDIS_URL', new ('redis://localhost:6379'))
    static accessor : URL;
}

What you get

  • Typed values. A fallback removes undefined from the return type. Converters convert numbers, booleans, bigint, JSON, URLs, dates, durations, and arrays, or pass your own function or a Standard Schema validator (zod, valibot, arktype).
  • Any source. A source is any object with a readVars() method. Bind process.env, a Cloudflare Workers binding, a browser bundle, or a secret store payload you fetched at boot. On Node, Bun, and Deno one binds on import.
  • Zero runtime dependencies. The reader, converters, and the built-in .env parser are self-contained, so nothing is added to your dependency tree.
  • .env loading built in on Node. The default Node source adds a per-environment file cascade, ${VAR} templates, and strict / required checks. It needs a filesystem, so off Node you pass values through another source.
  • The same API on Node, Bun, Deno, Cloudflare Workers, and the browser. See Compatibility.

Next

Start with the Quick Start, then the Envapter reader API.

On this page