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

smart-envx

v2.0.4

Published

A modern .env manager for Node.js — loads, validates, and auto-generates .env.example files with support for defaults, type checking, and environment-based loading.

Readme

smart-envx

A modern .env manager for Node.js — loads, validates, and auto-generates .env.example files with support for defaults, type checking, and environment-based loading.

npm version npm downloads license


Features

Load .env or .env.{mode} files easily
Fallback defaults if variables are missing
Validate environment variables with type checking
Auto-generate .env.example from loaded env
Support for dev / prod modes automatically
Lightweight — zero dependencies except dotenv
Simple API, TypeScript-friendly


Installation

npm install smart-envx

Or if you’re using Yarn:

yarn add smart-envx

Quick Example

const {
  loadEnv,
  validate,
  generateExample,
  loadByMode,
} = require("smart-envx");

// Load .env or .env.development automatically
loadByMode({
  PORT: "3000",
  DB_URL: "http://localhost:5000",
  DEBUG_MODE: "false",
});

// Validate required variables
validate(["PORT", "DB_URL"], {
  PORT: "number",
  DB_URL: "url",
  DEBUG_MODE: "boolean",
});

// Generate .env.example automatically
generateExample();

⚙️ API Reference

1 loadEnv(path = '.env', defaults = {})

Loads environment variables from a .env file and applies default values if missing.

loadEnv(".env", { PORT: "8080", MODE: "development" });

🟢 If .env file doesn’t exist, it uses existing process.env values or defaults.


2 validate(requiredVars, schema)

Validates presence and types of required environment variables.

Supported types:

  • string
  • number
  • boolean
  • url
validate(["PORT", "API_KEY"], { PORT: "number", API_KEY: "string" });

❌ If any variable is missing or has the wrong type, it logs an error and stops the process.


3 generateExample(filePath = '.env.example')

Automatically generates (or updates) an .env.example file with all current environment keys.

generateExample();

4 loadByMode(defaults = {})

Automatically loads .env.development or .env.production based on your NODE_ENV.

process.env.NODE_ENV = "production";
loadByMode({ PORT: "4000" }); // loads .env.production

If NODE_ENV isn’t set, it defaults to development.


Example Folder Structure

project/
├── .env.development
├── .env.production
├── .env.example
├── index.js
└── package.json

Example .env file

PORT=4000
DB_URL=https://example.com/db
DEBUG_MODE=true

Example Output

When you run your app:

 Loading environment: development
 Applied default: DB_URL=http://localhost:5000
Environment variables validated successfully!
Example .env file generated at .env.example

Why Use smart-envx?

| Problem | Solution | | ---------------------------------- | ----------------------------------------------- | | Missing .env variables crash app | Automatically applies safe defaults | | No clear .env.example | Auto generates and syncs one | | Hard to validate env types | Built-in type validator | | Switching between dev/prod | loadByMode() loads correct file automatically |


Author

Developed with by Saad

GitHub: @saad npm: @nextgen78


License

MIT License — free to use, modify, and distribute.


Support the Project

If you like smart-envx, consider:

  • ⭐ Starring the repo on GitHub
  • 🐦 Sharing it on Twitter / LinkedIn
  • 💡 Using it in your open-source projects!