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

envdiff

v0.0.1

Published

Compare .env files and find missing or different variables instantly

Readme

envdiff

Compare .env files and find missing or different variables instantly

npm version License: MIT

Problem

Dev works, staging fails. What env vars are different?

Solution

envdiff compares .env files and shows differences clearly — find that missing variable in seconds, not hours.

Features

  • Instant comparison - See differences at a glance
  • Smart masking - Sensitive values are masked by default
  • Export missing vars - Generate file with missing variables
  • Validate against example - Check .env against .env.example
  • CI/CD ready - Exit code 1 when differences found
  • JSON output - For scripting and automation

Installation

# Run directly with npx (recommended)
npx envdiff .env.development .env.staging

# Or install globally
npm install -g envdiff

# Or as dev dependency
npm install --save-dev envdiff

Usage

Compare Two Files

# Basic comparison
npx envdiff .env.development .env.staging

# Show all values (including sensitive)
npx envdiff .env.development .env.staging --show-values

# Show identical variables too
npx envdiff .env.development .env.staging --show-identical

# Output as JSON
npx envdiff .env.development .env.staging --json

Export Missing Variables

# Export variables missing from second file
npx envdiff .env.development .env.staging --export missing.env

# Export from the other direction
npx envdiff .env.staging .env.development --export missing.env

Validate Against Example

# Check if .env has all variables from .env.example
npx envdiff validate .env .env.example

# Strict mode: fail if .env has extra variables
npx envdiff validate .env .env.example --strict

Example Output

🔍 Environment Comparison
──────────────────────────────────────────────────

Comparing:
  1. .env.development
  2. .env.staging

❌ Missing in .env.staging:
   • STRIPE_WEBHOOK_SECRET
   • REDIS_URL
   • DEBUG_MODE

⚠️  Missing in .env.development:
   • SENTRY_DSN
   • CDN_URL

🔄 Different values:
   • API_URL
     File 1: http://localhost:3000
     File 2: https://api-staging.example.com
   • DATABASE_URL
     File 1: postgres://localhost:5432/dev
     File 2: postgres://staging-db:5432/staging

✅ Identical: 23 variables

──────────────────────────────────────────────────
Summary:
   Missing in file 1: 2
   Missing in file 2: 3
   Different values:  2
   Identical:         23

💡 Tip: Use --export <file> to export missing variables
──────────────────────────────────────────────────
Found the bug in seconds? Consider supporting:
☕ https://buymeacoffee.com/willzhangfly

Validation Example

$ npx envdiff validate .env .env.example

🔍 Environment Validation
──────────────────────────────────────────────────

❌ Missing required variables:
   • DATABASE_URL
   • JWT_SECRET

⚠️  Extra variables not in example:
   • DEBUG_MODE
   • LOCAL_ONLY_VAR

CLI Options

Compare Command

Usage: envdiff <file1> <file2> [options]

Arguments:
  file1                    First .env file
  file2                    Second .env file

Options:
  --json                   Output results as JSON
  --show-identical         Show identical variables
  --show-values            Show all values (including sensitive)
  --export <file>          Export missing variables to a file
  --export-from <source>   Source for export: "first" or "second"
  -V, --version            Output version number
  -h, --help               Display help

Validate Command

Usage: envdiff validate <env-file> <example-file> [options]

Arguments:
  env-file                 Your .env file
  example-file             The .env.example template

Options:
  --strict                 Fail if env has extra variables
  -h, --help               Display help

CI/CD Integration

# GitHub Actions
- name: Validate environment
  run: npx envdiff validate .env .env.example

# Compare staging vs production config
- name: Compare environments
  run: |
    npx envdiff .env.staging .env.production --json > env-diff.json
    if [ $? -ne 0 ]; then
      echo "Environment files differ!"
      cat env-diff.json
    fi

Programmatic Usage

import { compareEnvFiles, areIdentical } from 'envdiff';

const result = compareEnvFiles('.env.development', '.env.staging');

console.log('Missing in staging:', result.missingInSecond);
console.log('Different values:', result.different);

if (areIdentical(result)) {
  console.log('Files are identical!');
}

Security

By default, envdiff masks values for keys containing:

  • secret, password, key, token
  • auth, credential, private, api_key

Use --show-values to display all values.

Comparison with Alternatives

| Tool | .env Aware | Visual Diff | Export | Validate | npm Native | |------|------------|-------------|--------|----------|------------| | envdiff | ✅ | ✅ | ✅ | ✅ | ✅ | | diff command | ❌ | ⚠️ | ❌ | ❌ | N/A | | dotenv-safe | ❌ | ❌ | ❌ | ✅ | ✅ | | envalid | ❌ | ❌ | ❌ | ✅ | ✅ |

Requirements

  • Node.js 18.0.0 or higher

Contributing

Contributions welcome! Ideas:

  • Support for encrypted .env files
  • Integration with secret managers
  • VS Code extension

Support

This project is maintained in my free time. If it helped you find that missing variable faster, I'd really appreciate your support:

Thank you to everyone who has contributed, shared feedback, or helped spread the word!

License

MIT


Made with ❤️ for faster debugging