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 🙏

© 2025 – Pkg Stats / Ryan Hefner

envase

v1.0.2

Published

Type-safe environment variable validation with Standard Schema compliance

Readme

Envase

Type-safe environment variable validation with Standard Schema compliance. Works with Zod, Valibot, ArkType, and other Standard Schema-compatible validation libraries.

"Envase" is Spanish for "container" - reflecting how this library encapsulates environment variables in a safe, structured, and validated way.

Highlights

  • 🔒 Type-safe validation - Full TypeScript type inference
  • 🔌 Standard Schema compliant - Works with any compatible validation library
  • 🌐 Runtime agnostic - Runs anywhere (Node, Bun, Deno, browsers)
  • 🏗️ Structured configuration - Supports nested config objects
  • 🚦 Environment detection - isProduction, isTest, isDevelopment flags
  • 📜 Detailed error reporting - See all validation failures at once
  • 🚀 Lightweight - Single dependency (type-fest), zero runtime overhead

Installation

npm install envase

Note: This package is ESM-only. It does not support CommonJS require(...).

Validation Library Support

Built on the Standard Schema specification, Envase works seamlessly with any schema library that implements the spec. See the full list of compatible libraries.

Popular options include:

Key features

Type-Safe Validation of Nested Schema

import { parseEnv, envvar } from 'envase';
import { z } from 'zod';

const config = parseEnv(process.env, {
  app: {
    listen: {
      port: envvar('PORT', z.coerce.number().int().min(0).max(65535)),
    },
  },
  db: {
    host: envvar('DB_HOST', z.string().min(1).default('localhost')),
  },
  apiKey: envvar('API_KEY', z.string().min(32).optional()),
});
// config.app.listen.port -> number
// config.db.host -> string
// config.apiKey -> string | undefined

Environment Detection

import { detectNodeEnv } from 'envase';

const nodeEnv = detectNodeEnv(process.env);
// nodeEnv.isProduction -> boolean
// nodeEnv.isTest -> boolean
// nodeEnv.isDevelopment -> boolean

These flags are inferred from the NODE_ENV value (i.e. 'production', 'test', or 'development').

Detailed error reporting

import { parseEnv, envvar, EnvaseError } from 'envase';
import { z } from 'zod';

try {
  parseEnv(process.env, {
    apiKey: envvar('API_KEY', z.string().min(32)),
    db: {
      host: envvar('DB_HOST', z.string().min(1)),
    },
  });
} catch (error: unknown) {
  if (EnvaseError.isInstance(error)) {
    error.message
    // Environment variables validation has failed:
    //   [API_KEY]:
    //     String must contain at least 32 character(s)
    //     (received: "short")
    //
    //   [DB_HOST]:
    //     Required
    //     (received: "undefined")

    error.issues
    //  [
    //    {
    //      "name": "API_KEY",
    //      "value": "short",
    //      "messages": ["String must contain at least 32 character(s)"]
    //    },
    //    {
    //      "name": "DB_HOST",
    //      "value": undefined,
    //      "messages": ["Required"]
    //    }
    //  ]
  }
}

Type Inference

import { envvar, type InferEnv } from 'envase';
import { z } from 'zod';

const envSchema = {
  apiKey: envvar('API_KEY', z.string().min(32)),
  db: {
    host: envvar('DB_HOST', z.string().min(1)),
  },
};

type Config = InferEnv<typeof envSchema>;
// { apiKey: string; db: { host: string } }

API Reference

envvar

envvar(name: string, schema: StandardSchemaV1<T>)

Wraps a variable name and its schema for validation. This helps pair the raw env name with the shape you expect it to conform to.

parseEnv

parseEnv(env: Record<string, string | undefined>, envSchema: T)

Validates envvars against the schema and returns a typed configuration object.

detectNodeEnv

detectNodeEnv(env: Record<string, string | undefined>)

Standalone utility that reads NODE_ENV and returns an object with the following boolean flags:

  • isProduction: true if NODE_ENV === 'production'
  • isTest: true if NODE_ENV === 'test'
  • isDevelopment: true if NODE_ENV === 'development'

EnvaseError

Thrown when validation fails.

Contains:

  • message: Human-readable error summary
  • issues: Array of validation issues with:
    • name: Environment variable name
    • value: Invalid value received
    • messages: Validation error messages

Why Envase?

  • ✅ Works with any schema lib that follows the Standard Schema spec
  • 🔄 Supports deeply nested configs
  • 🔍 Offers rich error reporting with detailed issue breakdowns

Contributing

Contributions are welcome! If you’d like to improve this package, feel free to open an issue or submit a pull request. 🚀