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

ts-env-guard

v1.0.1

Published

Validate .env files against .env.example or a JSON schema

Readme

env-guard — Validate Environment Variables Before Deploy

npm version npm downloads CI TypeScript License: MIT Zero dependencies

Stop deploying with missing env vars. A zero-dependency CLI and library that validates .env files against .env.example or a JSON schema — one command catches them before your app does.

$ npx env-guard
✗ Environment validation failed:
  • DATABASE_URL: Missing variable
  • API_KEY: Missing variable

Validate .env files against .env.example or a JSON schema. CLI + library. Zero dependencies.

env-guard CLI demo — validating .env against .env.example and catching missing variables

Quick Start

# Zero config — checks .env against .env.example
npx env-guard
✓ All environment variables validated.

or when variables are missing:

✗ Environment validation failed:

  • DATABASE_URL: Missing variable
  • API_KEY: Missing variable

Install

npm install env-guard

CLI Usage

# Default: validate .env against .env.example
npx env-guard

# Custom paths
npx env-guard --env .env.local --example .env.template

# Validate against a JSON schema
npx env-guard --schema env-schema.json

| Flag | Description | Default | | ----------- | ------------------------- | -------------- | | --env | Path to .env file | .env | | --example | Path to .env.example file | .env.example | | --schema | Path to JSON schema file | (none) |

Exit code is 0 when valid, 1 when validation fails.

Library Usage

import { envGuard } from "env-guard";

const result = envGuard();

if (!result.valid) {
  console.error("Missing:", result.missing);
  console.error("Errors:", result.errors);
  process.exit(1);
}

With custom paths

const result = envGuard({
  envPath: ".env.local",
  examplePath: ".env.template",
});

With JSON schema

const result = envGuard({
  schemaPath: "env-schema.json",
});

JSON Schema Format

Create a JSON file where each key is an env variable name:

{
  "PORT": { "required": true, "pattern": "^\\d+$" },
  "NODE_ENV": { "enum": ["development", "production", "test"] },
  "DEBUG": { "required": false },
  "API_KEY": true,
  "OPTIONAL_VAR": false
}

| Rule | Type | Description | | ---------- | ---------- | ------------------------------------------------- | | required | boolean | Whether the variable must exist (default: true) | | pattern | string | Regex pattern the value must match | | enum | string[] | Allowed values | | true | — | Shorthand for { required: true } | | false | — | Shorthand for { required: false } |

API

envGuard(options?): ValidationResult

| Option | Type | Default | Description | | ------------- | -------- | ---------------- | -------------------- | | envPath | string | ".env" | Path to .env file | | examplePath | string | ".env.example" | Path to example file | | schemaPath | string | — | Path to JSON schema | | cwd | string | process.cwd() | Working directory |

ValidationResult

interface ValidationResult {
  valid: boolean;
  missing: string[];
  extra: string[];
  errors: ValidationError[];
}

validateAgainstExample(envVars, exampleVars): ValidationResult

Lower-level function for programmatic use with pre-parsed env maps.

validateAgainstSchema(envVars, schema): ValidationResult

Lower-level function for programmatic use with a schema object.

parseEnvFile(content): Map<string, string>

Parse a .env file string into a Map. Handles comments, quotes, empty lines.

Author

Ofer Shapira

LinkedIn GitHub

License

MIT © Ofer Shapira