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

env-sanity

v0.1.0

Published

Environment file validator and sync utility.

Downloads

85

Readme

env-sanity

Environment file validator and sync utility for teams

npm version License: MIT

A simple, powerful tool to keep your environment files in sync across different environments. Perfect for teams working with multiple .env files (.env.prod, .env.qa, .env.staging, etc.).

✨ Features

  • 🔍 Compare environment files against templates
  • 🔄 Sync missing keys across environments
  • 📁 Smart file resolution (finds .env.prod, .prod, etc.)
  • 💬 Interactive confirmation before making changes
  • 🏗️ CI/CD friendly with proper exit codes
  • 📦 Dual usage: CLI tool + importable library

🚀 Quick Start

Installation

# Global installation (recommended for CLI usage)
npm install -g env-sanity

# Or use with npx (no installation needed)
npx env-sanity --help

Basic Usage

# Compare your .env against template
env-sanity compare .env .env.example

# Sync missing keys from master to targets
env-sanity sync --master .env.prod .env.qa .env.staging

# Compare multiple files against master
env-sanity compare-master --master .env.prod .env.qa .env.staging

📖 Commands

compare <actual> <template>

Compare an actual environment file against a template/reference file.

env-sanity compare .env .env.example
env-sanity compare .env.qa .env.prod

Output:

🔍 Comparing .env against template .env.example
⚠️  Missing in .env (required by template): DATABASE_NAME, STRIPE_SECRET_KEY
➕  Extra in .env (not in template): LOCAL_DEV_MODE

sync --master <file> <targets...>

Add missing keys from master file to target files with empty placeholders.

env-sanity sync --master .env.example .env
env-sanity sync --master .env.prod .env.qa .env.staging

Features:

  • ✅ Preserves comments and file structure
  • ✅ Interactive confirmation before changes
  • ✅ Safe empty placeholders (no value copying)

compare-master --master <file> <targets...>

Compare multiple files against a master file (great for CI/CD).

env-sanity compare-master --master .env.prod .env.qa .env.staging

📁 File Resolution

env-sanity automatically finds your environment files using smart patterns:

env-sanity compare .prod .qa
# Tries: .prod, .env.prod, .env.prod
# Tries: .qa, .env.qa, .env.qa

Search locations:

  1. Current directory
  2. environment/ directory (if exists)

🔧 Programmatic Usage

Use env-sanity as a library in your Node.js projects:

import { compareEnvs, parseEnvFile } from "env-sanity";

const env1 = parseEnvFile(".env");
const env2 = parseEnvFile(".env.example");

const result = compareEnvs(env1, env2);
console.log("Missing keys:", result.missing);
console.log("Extra keys:", result.extra);

🏗️ CI/CD Integration

env-sanity returns proper exit codes for CI/CD pipelines:

# GitHub Actions example
- name: Validate environment files
  run: env-sanity compare .env.example .env.prod
  • Exit code 0: Files are in sync ✅
  • Exit code 1: Differences found ❌

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

👨💻 Author

Created and maintained by Jeffrey Davies

📄 License

MIT © Jeffrey Davies

🙏 Acknowledgments

Built with:

  • TypeScript - Type safety and modern JavaScript features
  • Node.js - JavaScript runtime environment
  • commander.js - Powerful CLI framework with subcommands
  • dotenv - Environment file parsing and validation