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

safe-env-sync

v1.0.2

Published

Environment validation and synchronization toolkit

Readme

safe-env-sync

Type-safe environment validation, diagnostics, and schema management for Node.js + TypeScript applications.

safe-env-sync upgrades traditional .env handling into a structured, validated, and developer-friendly configuration system.

Instead of treating environment variables as untyped strings, it treats them like configuration contracts.


✨ Features

🔍 Environment Validation

Validate required environment variables with schema-based rules.

Supports:

  • string
  • number
  • boolean
  • enum

🧠 Type-Safe Parsing

Automatically converts environment variables into proper runtime types.

env.PORT // number
env.DEBUG // boolean

instead of raw strings.


⚡ Doctor Command (Flagship Feature)

Run full environment diagnostics.

Detects:

  • missing variables
  • unused variables
  • schema mismatches
  • .env.example drift
npx safe-env-sync doctor

Example output:

✖ Missing Variables
  DATABASE_URL

⚠ Unused Variables
  OLD_API_KEY

⚠ Drift Detected
  .env.example missing:
    REDIS_URL

✔ Validation complete

🧩 Schema Definition

Define environment contracts centrally using defineEnv().

import { defineEnv } from "safe-env-sync";

export default defineEnv({
  PORT: {
    type: "number",
    required: true,
  },

  JWT_SECRET: {
    type: "string",
    required: true,
  },

  NODE_ENV: {
    type: "enum",
    values: ["development", "production"],
    required: true,
  },
});

🛠 Interactive Initialization

Generate schemas interactively from existing .env files.

npx safe-env-sync init --interactive

📄 Generate .env.example

Automatically generate .env.example from schema definitions.

npx safe-env-sync generate

🔄 Compare Environment Files

Compare two environment files.

Useful for:

  • staging vs production
  • local vs production
  • CI verification
npx safe-env-sync compare .env .env.production

🧹 Unused Variable Detection

Detect variables present in .env but missing from schema definitions.


🌊 Drift Detection

Ensure .env.example stays synchronized with the actual schema.


📦 Installation

npm install safe-env-sync

🚀 Quick Start

1. Create a schema

safe-env.config.ts

import { defineEnv } from "safe-env-sync";

export default defineEnv({
  PORT: {
    type: "number",
    required: true,
  },

  JWT_SECRET: {
    type: "string",
    required: true,
  },

  NODE_ENV: {
    type: "enum",
    values: ["development", "production"],
    required: true,
  },
});

2. Create your .env

PORT=5000
JWT_SECRET=mysecret
NODE_ENV=development

3. Validate your environment

npx safe-env-sync validate

📚 CLI Commands

| Command | Description | | -------------------- | -------------------------------- | | validate | Validate environment variables | | doctor | Run full environment diagnostics | | generate | Generate .env.example | | compare | Compare two env files | | init | Generate schema from .env | | init --interactive | Interactive schema builder |


🧠 Why safe-env-sync?

Traditional .env handling often leads to:

  • runtime crashes
  • missing secrets
  • invalid types
  • stale .env.example files
  • onboarding confusion

safe-env-sync solves this with:

  • schema enforcement
  • runtime validation
  • type-safe parsing
  • environment diagnostics
  • drift detection

🏗 Philosophy

Environment variables are configuration code, not hidden strings.


🛣 Roadmap

Upcoming features:

  • doctor --fix
  • GitHub Action integration
  • watch mode
  • stronger enum inference
  • schema patching
  • monorepo support

📄 License

MIT