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

env-utility

v1.0.1

Published

A robust utility to validate environment variables against `env.d.ts` type definitions, generate TypeScript types from `.env` files, and ensure your application runs with correct configurations. This tool supports custom regex validation, enums, and envir

Readme

Environment Variable Validator

A robust utility to validate environment variables against env.d.ts type definitions, generate TypeScript types from .env files, and ensure your application runs with correct configurations. This tool supports custom regex validation, enums, and environment-specific overrides.

Features

  1. Type Validation:

    • Validate environment variables against a env.d.ts file.
    • Support for strings, enums, and custom regex patterns.
  2. Regex Validation:

    • Define regex patterns directly in the env.d.ts file using @regex tags.
    • Supports multiple regex patterns per variable. By adding inline comment next to the variable defintion in the env.d.ts
  3. Customizable env.d.ts:

    • Generate a basic env.d.ts file from your .env file.
    • Developers can modify the generated file to include enums, regex patterns.

Installation

Install using npm

npm install env-utility

Usage

Make sure you have a env.d.ts file.

  • An example to .env and env.d.ts files:

    env.d.ts file supports both enum and regex. You can add regex by adding inline comment next to the variable by using @regex tag

    .env

    API_URL=https://api.example.com
    NODE_ENV=development
    PORT=3000

    env.d.ts

    enum NodeEnv {
    development = "development",
    production = "production",
    }
    
    interface ProcessEnv {
    API_URL: string; // @regex ^https?://[a-zA-Z0-9.-]+$ @regex ^ftp://[a-zA-Z0-9.-]+$
    NODE_ENV: NodeEnv;
    PORT: string; // @regex ^\d+$
    }
    • To generate basic env.d.ts from .env file:
        env-utility generate
        Options:
          -e, --env-file  Path to the .env file             [string] [default: "./.env"]
          -d, --dts-file  Path to the env.d.ts file     [string] [default: "./env.d.ts"]
  • You have to ways to validate the env, either from CLI or importing validateEnv in you code :

    • CLI:

      env-utility validate
      Options:
      -e, --env-file Path to the .env file [string] [default: "./.env"]
      -d, --dts-file Path to the env.d.ts file [string] [default: "./env.d.ts"]

      Add to your package.json

      ```json
      {
        "scripts": {
          "prebuild": "env-utility validate"
        }
      }
      ```
    • Import validateEnv:

      import { validateEnv } from "env-utility";
      validateEnv();

From the example above, if you have invalid .env file:

API_URL=https2://api.example.com
NODE_ENV=developments
PORT=3000

The output will be:

Environment variable validation failed:
- API_URL: API_URL does not match any of the required patterns: ^https?://[a-zA-Z0-9.-]+$, ^ftp://[a-zA-Z0-9.-]+$
- NODE_ENV: Invalid enum value. Expected 'development' | 'production', received 'developments'