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

envconfig-kit

v0.1.0

Published

Type-safe environment variables with fail-fast validation

Readme

envconfig-kit

Type-safe environment variables with fail-fast validation. Zero dependencies.

npm version npm downloads build node bundle size license

Why?

  • Built-in .env loading - no need for dotenv
  • Type-safe - full TypeScript inference
  • Zero dependencies - 3KB minified
  • Fail-fast validation - catches errors at startup
  • Actionable error messages - tells you exactly how to fix issues
  • CLI tools - generate .env.example, validate, health checks
  • Transform support - parse and sanitize values
  • Multi-environment - .env.development, .env.production, etc.

Install

npm install envconfig-kit

Quick Start

import { env } from 'envconfig-kit'

const config = env({
  PORT: { type: 'number', default: 3000 },
  API_KEY: { type: 'string' },
  DEBUG: { type: 'boolean', default: false },
  DATABASE_URL: { type: 'url' },
})

// config.PORT is typed as number
// config.API_KEY is typed as string
// Throws on startup if API_KEY or DATABASE_URL is missing

No need for dotenv - envconfig-kit automatically loads .env files.

Built-in .env Loading

envconfig-kit automatically loads environment variables from:

  • .env
  • .env.local
  • .env.development (based on NODE_ENV)
  • .env.production (based on NODE_ENV)
const config = env({ 
  PORT: { type: 'number' } 
})
// Automatically loads from .env files

Supported Types

| Type | Validates | Example | |------|-----------|---------| | string | Any string | "hello" | | number | Valid number | "3000"3000 | | boolean | true/false, 1/0, yes/no | "true"true | | url | Valid URL with protocol | "https://api.example.com" | | email | Valid email format | "[email protected]" | | port | Number between 0-65535 | "3000"3000 |

Schema Options

env({
  API_KEY: { type: 'string' },
  PORT: { type: 'number', default: 3000 },
  OPTIONAL_VAR: { type: 'string', optional: true },
  TAGS: { 
    type: 'string',
    transform: (value) => value.split(',') 
  },
})

Error Messages

When validation fails, you get clear errors with fix suggestions:

❌ Environment validation failed:

  API_KEY: Missing required environment variable
  ➜ Fix: Add to .env file
    Example: API_KEY=your-value-here

  PORT: Expected number, got "abc"
  ➜ Fix: Provide a valid number
    Example: PORT=3000

  Run your app with valid environment variables or add them to .env

CLI Tools

# Initialize envconfig-kit in your project
npx envconfig-kit init

# Validate .env file
npx envconfig-kit check

# Generate .env.example
npx envconfig-kit generate

# Health check
npx envconfig-kit doctor

Built-in .env Loading

envconfig-kit automatically loads environment variables from:

  • .env
  • .env.local
  • .env.development (based on NODE_ENV)
  • .env.production (based on NODE_ENV)

Priority order:

  1. process.env (highest)
  2. .env.local
  3. .env.${NODE_ENV}
  4. .env (lowest)

Transform Values

const config = env({
  ALLOWED_ORIGINS: {
    type: 'string',
    transform: (value) => value.split(',')
  },
  API_URL: {
    type: 'url',
    transform: (value) => value.replace(/\/$/, '')
  }
})

Export Schema

import { schemaToMarkdown, schemaToJSON, generateDotenvExample } from 'envconfig-kit'

const schema = {
  PORT: { type: 'number', default: 3000 },
  API_KEY: { type: 'string' },
}

// Generate markdown table for docs
console.log(schemaToMarkdown(schema))

// Generate .env.example
console.log(generateDotenvExample(schema))

// Export as JSON
console.log(schemaToJSON(schema))

Advanced Usage

import { env } from 'envconfig-kit'

const config = env({
  DATABASE_URL: { type: 'url' },
  API_KEY: { type: 'string' },
  PORT: { type: 'number', default: 3000 },
  HOST: { type: 'string', default: 'localhost' },
  DEBUG: { type: 'boolean', default: false },
  REDIS_URL: { type: 'url', optional: true },
  CORS_ORIGINS: {
    type: 'string',
    default: 'http://localhost:3000',
    transform: (value) => value.split(',').map(s => s.trim())
  },
})

// TypeScript knows the exact types
config.PORT // number
config.API_KEY // string
config.DEBUG // boolean
config.REDIS_URL // string | undefined
config.CORS_ORIGINS // string[] (after transform)

License

MIT