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

@bonhomie/env-kit

v1.0.0

Published

Typed, validated environment variables for Node.js. Schema-based, collects all errors at once, zero dependencies.

Readme

@bonhomie/env-kit

Typed, validated environment variables for Node.js.

No more if (!process.env.X) throw new Error(...) scattered across 10 files. Define a schema once — env-kit validates at startup, collects all errors before throwing, and returns a frozen, typed object.

npm license zero deps


📦 Installation

npm install @bonhomie/env-kit

Quick Start

import { createEnv } from "@bonhomie/env-kit";

export const env = createEnv({
  NODE_ENV:     { type: "string",  enum: ["development", "production", "test"], default: "development" },
  PORT:         { type: "port",    default: 3000 },
  DATABASE_URL: { type: "url",     required: true },
  JWT_SECRET:   { type: "string",  required: true, minLength: 32 },
  ADMIN_EMAIL:  { type: "email",   required: false },
  ENABLE_CACHE: { type: "boolean", default: false },
  MAX_UPLOAD:   { type: "number",  min: 1, max: 100, default: 10 },
  FEATURES:     { type: "json",    default: {} },
});

// All values are typed and coerced
console.log(env.PORT);         // number: 3000
console.log(env.ENABLE_CACHE); // boolean: false
console.log(env.FEATURES);     // object: {}

If any field fails, startup throws with all errors at once:

Environment validation failed — 2 errors:

  ✗  DATABASE_URL: is required but was not provided
  ✗  JWT_SECRET: must be at least 32 characters

Types

| Type | Accepts | Returns | | --------- | -------------------- | ----------------- | | string | Any string | string (trimmed)| | number | "42", "3.14" | number | | integer | "7", "100" | number (integer)| | boolean | true/false/1/0/yes/no/on/off | boolean | | port | "3000", "8080" | number (1–65535)| | url | "https://..." (full URL) | string | | email | "[email protected]" | string | | json | '{"key":"val"}' | Parsed value |


Field Options

| Option | Type | Description | | ------------ | ----------------- | ------------------------------------------------------- | | type | FieldType | One of the types above. Default: "string". | | required | boolean | Default: true. Set false to make optional. | | default | any | Returned when the variable is missing. Makes optional automatically. | | enum | any[] | List of allowed values (checked after coercion). | | min | number | Minimum value for number/integer/port. | | max | number | Maximum value for number/integer/port. | | minLength | number | Minimum string length. | | maxLength | number | Maximum string length. | | validate | (v) => true\|string | Custom validator. Return true to pass, or an error string. | | description| string | Human-readable description (for documentation tooling). |


Custom Validator

const env = createEnv({
  JWT_SECRET: {
    type: "string",
    validate: (v) => v.length >= 32 || "must be at least 32 characters",
  },
  DATABASE_URL: {
    type: "url",
    validate: (v) => v.startsWith("postgresql://") || "must be a PostgreSQL URL",
  },
});

Custom Source

By default reads from process.env. Pass any object as the second argument for testing or alternative sources:

const env = createEnv(
  { PORT: { type: "port", default: 3000 } },
  { PORT: "4000" }  // custom source
);

Error Handling

import { createEnv, EnvError } from "@bonhomie/env-kit";

try {
  const env = createEnv(schema);
} catch (err) {
  if (err instanceof EnvError) {
    console.error(err.message);      // full formatted message
    console.error(err.fields);       // [{ field: "PORT", message: "..." }, ...]
  }
}

Notes

  • The result is Object.freezed — mutations are rejected in strict mode.
  • Whitespace-only values are treated as missing (prevents silent Number(" ") → 0 bugs).
  • Zero dependencies.

📄 License

MIT — Bonhomie