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

@envchecker/env-validator

v1.1.0

Published

A powerful environment variable validator for Node.js applications with schema validation, type checking, and security features

Readme

EnvChecker

A powerful Node.js tool for validating environment variables against a predefined schema. Ensure your application's configuration is correct before startup.

Features

Type Validation: Validate numbers, strings, URLs, JSON objects, and arrays 🔒 Security: Mark sensitive variables to prevent logging 🎯 Pattern Matching: Use regex patterns to validate formats 📝 Custom Validation: Add your own validation functions 🔄 Conditional Validation: Require variables based on conditions 🎨 Pretty Output: Colorized CLI output for better readability

Installation

npm install @envchecker/env-validator

Quick Start

  1. Install the package - it will automatically create a default envchecker.config.js file in your project root:
// Default envchecker.config.js
module.exports = {
  REQUIRED_VARIABLES: {
    PORT: {
      type: 'number',
      required: true,
      min: 1024,
      max: 65535
    },
    NODE_ENV: {
      type: 'string',
      required: true,
      allowedValues: ['development', 'staging', 'production']
    },
    DATABASE_URL: {
      type: 'url',
      required: true,
      pattern: '^postgres://'
    },
    API_KEY: {
      type: 'string',
      required: true,
      sensitive: true,
      minLength: 32
    }
  }
};

You can modify this file to match your project's requirements.

  1. Use in your code:
const { validateEnv } = require('@envchecker/env-validator');
const config = require('./envchecker.config.js');

try {
  validateEnv(config);
  console.log('Environment variables are valid!');
} catch (error) {
  console.error('Validation failed:', error.errors);
  process.exit(1);
}
  1. Or use the CLI:
npx @envchecker/env-validator

Configuration Options

Variable Types

  • string: Text values

    NAME: { type: 'string', minLength: 1, maxLength: 100 }
  • number: Numeric values

    PORT: { type: 'number', min: 1024, max: 65535 }
  • boolean: True/false values

    DEBUG: { type: 'boolean' }
  • url: URL strings

    API_URL: { type: 'url', pattern: '^https://' }
  • json: JSON objects with schema validation

    CONFIG: {
      type: 'json',
      schema: {
        host: { type: 'string', required: true },
        port: { type: 'number', required: true }
      }
    }
  • array: Array values

    ALLOWED_IPS: { type: 'array' }

Validation Options

  • required: Make a variable mandatory

    API_KEY: { type: 'string', required: true }
  • pattern: Validate against a regex pattern

    EMAIL: { type: 'string', pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$' }
  • sensitive: Mark variables as sensitive to prevent logging

    PASSWORD: { type: 'string', sensitive: true }
  • allowedValues: Restrict to specific values

    LOG_LEVEL: { type: 'string', allowedValues: ['debug', 'info', 'warn', 'error'] }
  • validate: Custom validation function

    VERSION: {
      type: 'string',
      validate: (value) => {
        if (!/^\d+\.\d+\.\d+$/.test(value)) {
          throw new Error('Must be a valid semantic version');
        }
      }
    }

Conditional Validation

Require variables based on conditions:

module.exports = {
  CONDITIONAL_VARIABLES: {
    SSL_CERT: {
      type: 'string',
      required: (env) => env.NODE_ENV === 'production'
    },
    REDIS_URL: {
      type: 'url',
      required: (env) => env.CACHE_ENABLED === 'true'
    }
  }
};

CLI Usage

# Basic validation
npx @envchecker/env-validator

# With verbose output
npx @envchecker/env-validator --verbose

# Using custom config file
npx @envchecker/env-validator --config ./config/env.config.js

Examples

Check out our examples directory for more detailed examples and use cases:

  • Basic validation
  • Advanced validation with conditional rules
  • Custom validation functions
  • Common configuration patterns

Contributing

We welcome contributions! Please check out our contributing guidelines for details.

License

MIT

Support