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-drift-check

v0.5.0

Published

CLI tool for .env validation, schema checking, drift detection, environment diff, git audit, and codebase scanning. Zero-code-change alternative to dotenv-safe and envalid.

Readme

env-drift-check

Detect .env drift, enforce schema validation, scan your codebase, diff environments, and audit git safety — zero config required.

npm version npm downloads License: MIT TypeScript Node.js Tests


npx env-drift-check

✔ Loaded: .env
✔ Base: .env.example

✖ Missing keys:
  - DATABASE_URL
  - STRIPE_SECRET_KEY

⚠ Unused keys:
  - OLD_API_KEY

❌ Validation failed: PORT must be a number

Fix interactively:

npx env-drift-check -i

Missing environment variables crash apps in production. Wrong types create silent bugs. Leaked .env files in git history are a permanent problem. env-drift-check catches all of this from the CLI — without touching your application code.

  • Compares .env against .env.example and reports missing, extra, and mismatched keys
  • Validates values against a schema (type, range, pattern, enum, email, URL)
  • Scans JS/TS source for process.env.* references — works even without a .env file
  • Flags low-entropy secrets using Shannon entropy math
  • Warns when NEXT_PUBLIC_, VITE_, or REACT_APP_ prefixed variables look like server secrets
  • Checks .env files against .gitignore, git tracking, and full git history
  • Splits .env into Kubernetes ConfigMap + Secret YAML
  • Validates docker-compose.yml environment blocks against your schema
  • Validates across all packages in a monorepo with per-package config

Installation

npm install --save-dev env-drift-check

Works with any Node.js ≥ 16 project.


Commands

npx env-drift-check                          # compare .env against .env.example
npx env-drift-check --strict                 # exit 1 on any issue (CI/CD)
npx env-drift-check --system-env --strict    # validate process.env (containers/serverless)
npx env-drift-check --watch                  # re-validate on file save
npx env-drift-check --format json            # JSON output
npx env-drift-check --format sarif           # SARIF for GitHub Security tab
npx env-drift-check -i                       # interactive setup wizard

npx env-drift-check scan                     # report env references vs .env.example
npx env-drift-check scan --fix               # create/update .env.example from found keys

npx env-drift-check diff .env.staging .env.production    # side-by-side diff of two .env files
npx env-drift-check audit                                # check .env files for git tracking/history leaks
npx env-drift-check gen-example                          # generate .env.example from .env (strips values)
npx env-drift-check gen-configmap                        # split .env into K8s ConfigMap + Secret YAML
npx env-drift-check validate-compose                     # validate docker-compose.yml env blocks
npx env-drift-check monorepo --packages "packages/*"     # validate across all packages, aggregate results
npx env-drift-check init                                 # scaffold envwise.config.json + .env.example

Configuration

envwise.config.json is optional. Add it when you need type validation or custom rules:

{
  "baseEnv": ".env.example",
  "rules": {
    "PORT":         { "type": "number",  "min": 1024, "max": 65535 },
    "NODE_ENV":     { "type": "enum",    "values": ["development", "staging", "production"] },
    "DEBUG_MODE":   { "type": "boolean", "mustBeFalseIn": "production" },
    "DATABASE_URL": { "type": "url",     "required": true },
    "ADMIN_EMAIL":  { "type": "email" },
    "API_KEY":      { "type": "regex",   "regex": "^sk_(test|live)_[0-9a-zA-Z]{24}$" },
    "JWT_SECRET":   { "type": "string",  "checkSecretStrength": true },
    "OLD_KEY":      { "type": "string",  "deprecated": "Use NEW_KEY instead." }
  }
}

Validation types

| Type | Options | Notes | |---|---|---| | string | min, max, checkSecretStrength | Entropy check auto-enabled for keys named *SECRET*, *PASSWORD* | | number | min, max | | | boolean | mustBeFalseIn, mustBeTrueIn | Enforce flags per environment | | enum | values: [] | | | email, url, regex | regex for regex type | |

Rule options

| Option | Description | |---|---| | required | Defaults to true. Set false to make optional. | | default | Fallback value — key is never reported missing. | | requiredIf | Required only when another key matches a value: { "STORAGE": "s3" } | | deprecated | Emits a warning. Pass a string for a migration message. | | description | Shown in interactive prompts. |

Config inheritance

{
  "extends": "../base.config.json",
  "rules": {
    "DATABASE_URL": { "type": "url", "required": true }
  }
}

Child rules override parent on conflict. Circular references exit with an error.


CI/CD

A ready-to-use workflow is at .github/workflows/env-check.yml.

- name: Check environment drift
  run: npx env-drift-check --system-env --strict
  env:
    DATABASE_URL: ${{ secrets.DATABASE_URL }}
    API_SECRET_KEY: ${{ secrets.API_SECRET_KEY }}

Or use the marketplace action:

- uses: shashi089/env-drift-check@v1
  with:
    command: check
    strict: 'true'

Pre-commit hook

npm install --save-dev husky
npx husky init
echo "npx env-drift-check --strict" > .husky/pre-commit

With lint-staged (only runs when .env.example or the config changes):

{
  "lint-staged": {
    ".env.example": "npx env-drift-check --strict",
    "envwise.config.json": "npx env-drift-check --strict"
  }
}

Programmatic usage

import { checkDrift, loadConfig, parseEnv, report } from 'env-drift-check';

const config = loadConfig();
const base = parseEnv('.env.example');
const target = parseEnv('.env');

const result = checkDrift(base, target, config);
if (result.missing.length || result.errors.length) {
  report(result);
  process.exit(1);
}

See the API reference for all exports. examples/demo-app has a real-world integration.


vs. similar tools

| Feature | dotenv-safe | envalid | dotenv-linter | dotenvx | env-drift-check | | :--- | :---: | :---: | :---: | :---: | :---: | | Missing key detection | ✅ | ✅ | ✅ | ⚠️ basic | ✅ | | Runtime library | ✅ | ✅ | ❌ | ✅ | ⚠️ secondary | | CI/CD friendly | ✅ | ✅ | ✅ | ✅ | ✅ | | Encryption | ❌ | ❌ | ❌ | ✅ | ❌ | | Standalone CLI | ❌ | ❌ | ✅ | ✅ | ✅ | | Schema validation (no code changes) | ❌ | ❌ | ❌ | ❌ | ✅ | | Interactive fix wizard | ❌ | ❌ | ❌ | ❌ | ✅ | | Codebase scanner | ❌ | ❌ | ❌ | ❌ | ✅ | | Entropy-based secret scoring | ❌ | ❌ | ❌ | ❌ | ✅ | | Git safety audit | ❌ | ❌ | ❌ | ❌ | ✅ | | Environment diff | ❌ | ❌ | ✅ | ❌ | ✅ | | Framework prefix safety | ❌ | ❌ | ❌ | ❌ | ✅ | | Docker / Kubernetes support | ❌ | ❌ | ❌ | ❌ | ✅ |


Examples


CHANGELOG · ROADMAP · MIT License · Issues


If this saved you time, a ⭐ on GitHub helps others find it.