npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

envus

v2.0.0

Published

A zero-dependency schema system for clean, reliable env configs.

Readme

envus

npm version license

A zero-dependency environment configuration and validation library for Node.js. It provides a clear and explicit schema-based API for reading and validating environment variables, with support for nested config objects, default values, strict mode, and optional .env loading.


Features

API Reference

loadEnv(options?)

Lightweight .env loader.

loadEnv({
  path?: string;        // default: '.env'
  override?: boolean;   // default: false
  ignoreMissing?: boolean; // default: true
  forgiving?: boolean;  // default: true
  encoding?: BufferEncoding;
});

defineConfig(tree, options?)

Validates environment variables and returns a fully typed config object.

defineConfig(tree, {
  strict?: boolean;        // reject unknown env vars
  source?: Record<string, string | undefined>; // custom env source
  formatError?: (issues) => Error; // custom error formatter
});

schema(key)

Creates a schema builder for the given environment variable.

schema("NAME").string();
schema("PORT").number();
schema("DEBUG").boolean();
schema("MODE").enum(["dev", "prod"]);
schema("LIST").array();
schema("JSON").json();
schema("CUSTOM").custom(fn);

Common Modifiers

.required()
.optional()
.default(value)
.description(text)

Type-Specific Modifiers

String

.minLength(n)
.maxLength(n)
.pattern(regex)
.trim()

Number

.min(n)
.max(n)
.int()
.positive()
.negative()

Array

.of(schema("X").number())

Errors

EnvValidationError contains all collected validation errors.

try {
  defineConfig(...);
} catch (err) {
  console.error(err.issues);
}

  • Zero runtime dependencies
  • Explicit and type-friendly schema API
  • Nested configuration trees
  • Required, optional, defaulted, and constrained values
  • Lightweight .env loader (optional)
  • Works with both CommonJS and ESM
  • Strict mode to block unknown env vars

Installation

npm install envus

Basic Usage

import { loadEnv, defineConfig, schema } from "envus";

loadEnv(); // optional

const config = defineConfig({
  app: {
    name: "MyService",
    port: schema("PORT").number().min(1000).max(9999).default(3000),
    debug: schema("DEBUG").boolean().default(false),
  },
  security: {
    apiKey: schema("API_KEY").string().minLength(10).required(),
  },
  cache: {
    ttl: schema("CACHE_TTL").number().positive().default(3600),
  },
  features: {
    admins: schema("ADMINS").array().default(["root"]),
  }
});
```ts
import { loadEnv, defineConfig, schema } from "envus";

// Optional: load .env file
loadEnv();

const config = defineConfig({
  app: {
    name: "MyService",
    port: schema("PORT").number().default(3000),
  },
  db: {
    url: schema("DB_URL").string().required(),
    pool: schema("DB_POOL").number().default(5),
  }
});

console.log(config.app.port);

Schema Types

schema("KEY").string();
schema("KEY").number();
schema("KEY").boolean();
schema("KEY").enum(["dev", "prod"]);
schema("KEY").array();
schema("KEY").json();
schema("KEY").custom(raw => parseInt(raw || "0"));

Constraints

.required()
.optional()
.default(value)
.description(text)

Strict Mode

const config = defineConfig(schemaTree, {
  strict: true  // throws if extra env vars are present
});

Loading .env Files

loadEnv({ path: ".env.local", override: false });

Works alongside external dotenv loaders:

import "dotenv/config";

Error Handling

Errors are aggregated and thrown as EnvValidationError.

try {
  defineConfig({...});
} catch (err) {
  console.error(err);
}

Migration from v1

envus v2.0.0 is a complete rewrite of the library. The old API:

  • validateEnv()
  • resolveEnv()

has been removed, as the new schema-based system provides a more robust and type-safe configuration workflow.

If you rely on the old behavior, you can install the legacy version:

npm install [email protected]

What's New in v2

  • Explicit schema builder using schema("KEY")
  • Rich chaining API for validation (min, max, patterns, positive, etc.)
  • Nested config trees with defineConfig()
  • Optional .env loader with loadEnv()
  • Strong TypeScript inference
  • Strict mode for detecting unknown environment values
  • Zero runtime dependencies
  • More predictable and extensible architecture

License

MIT