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-checker-strict

v1.0.4

Published

Strict environment variable checker with autogenerated ENV_LIST and CLI support

Readme

env-checker-strict

Ever crashed your server on a weekend due to a missing environment variable? env-checker-strict is a strict and developer-friendly environment variable checker that ensures all required env vars are validated before your app runs. Add the env reference to version control, and catch issues in production — not during your downtime.

🚀 Why use this?

Managing environment variables in large codebases can be error-prone:

  • Missing env vars crash the app only during runtime ⚠️
  • You don't get autocomplete or type checking 🧠
  • Keeping track of all required keys is messy 📝

env-checker-strict solves these with a CLI that auto-generates a checkEnvAndThrowError() function and a typed ENVS accessor.

✨ Features

  • ✅ Throws on missing env vars at startup
  • 🧠 Generates ENVS object with keys for autocomplete and type safety
  • ⚙️ Supports both JavaScript and TypeScript
  • 🧪 Fully customizable CLI: skip keys, comment block, output file path
  • 📄 Auto-detects and parses .env file
  • 🔌 Auto injects required import and function call to entry file (optional with --inject flag) see CLI Options

📦 Installation

npm install -D env-checker-strict

For global CLI usage:

npm install -g env-checker-strict

🧑‍💻 CLI Usage

env-checker-strict --input .env --output env_checker.js --skip "SECRET,API_KEY" --ts

CLI Options

| Option | Alias | Description | Default | |---------------|-------|-----------------------------------------------------------------------------------------------|--------------------| | --input | -i | Path to .env file | .env | | --output | -o | Output file path for the generated checker | env_checker.js | | --skip | -s | Comma-separated list of env keys to skip from validation | (none) | | --comment | -c | Add a reminder comment at the top of .env to run env-checker-strict | true | | --ts | | Generate TypeScript output instead of JavaScript | false | | --inject | | Inject checkEnvAndThrowError() into the entry file. Optionally pass a path to the entry file | Read from package.json > main |

🔧 Example

Given .env

JWT_SECRET=supersecure
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
API_KEY=

CLI Run

env-checker-strict -i .env -o env_checker.ts --ts -s API_KEY

Output: env_checker.ts

// Auto-generated by env-checker-strict
// ⚠️ Do not modify manually

export const ENV_LIST: string[] = [
  'JWT_SECRET',
  'DB_HOST',
  'DB_USER',
  'DB_PASSWORD'
];

export interface ENVS {
  JWT_SECRET: string;
  DB_HOST: string;
  DB_USER: string;
  DB_PASSWORD: string;
}

export const ENVS: ENVS = {
  JWT_SECRET: process.env.JWT_SECRET as string,
  DB_HOST: process.env.DB_HOST as string,
  DB_USER: process.env.DB_USER as string,
  DB_PASSWORD: process.env.DB_PASSWORD as string
};

export const checkEnvAndThrowError = (): void => {
  for (const env of ENV_LIST) {
    if (!process.env[env]) {
      const message =
        `[ENV ERROR] Missing required environment variable: ${env}\n` +
        `➡️  Make sure '${env}' is defined in your .env file.\n` +
        `📄 Location: ${import.meta.url || 'env-checker.ts'}`;

      console.error(message);
      throw new Error(message);
    }
  }
};

✅ How to Use in Project

JavaScript (index.js)

const { checkEnvAndThrowError, ENVS } = require('./env_checker');
checkEnvAndThrowError();
console.log(ENVS.JWT_SECRET); // Autocomplete for all env vars

TypeScript (main.ts)

import { checkEnvAndThrowError, ENVS } from './env_checker';
checkEnvAndThrowError();
console.log(ENVS.JWT_SECRET); // Fully typed access

💡 Tips

  • Always run the CLI after updating your .env file.
  • Keep the generated file in source control (optional, but helpful).
  • Use the ENVS object across your app instead of process.env.

🪪 License

MIT — safe, free, and open.


Made with ❤️ to make your environment safer and your dev experience sharper.


PRs and suggestions welcome 🙌