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

@chinmayabehera/env-sentinel

v1.0.0

Published

Validate, coerce, and guard your environment variables at startup.

Readme

env-sentinel 🛡️

Validate, coerce, and guard your environment variables at startup.

env-sentinel ensures that your application fails fast and gracefully if required environment variables are missing, of the wrong type, or fail validation. It also provides type coercion (e.g., '3000'3000), defaults, and automatic .env.example generation.

Installation

npm install env-sentinel

Usage

const { sentinel } = require('env-sentinel');

const env = sentinel({
  PORT: { type: 'port', default: 3000, description: 'HTTP server port' },
  NODE_ENV: { type: 'string', enum: ['development', 'production', 'test'], default: 'development' },
  DATABASE_URL: { type: 'url', description: 'PostgreSQL connection string' },
  API_KEY: { type: 'string', validate: v => v.startsWith('sk-') || 'Must be a valid secret key' },
});

console.log(`Server starting on port ${env.PORT}`);
// `env` is fully typed, coerced, and guaranteed to be valid at this point.

Features

  • Coercion: Automatically converts string values to number, boolean, integer, json, url, etc.
  • Validation: Supports enum, regex, min/max ranges, and custom validation functions.
  • Missing Variable Checks: Throws descriptive errors when required variables are missing.
  • Fail Fast: Optionally throws, logs, or silently ignores validation errors.
  • Example Generation: Easily generate a .env.example file based on your schema.
  • TypeScript Support: First-class TS definitions provided out of the box.

API

sentinel(schema, [source], [options])

Validates and returns your environment variables.

  • schema: An object detailing your variable constraints.
  • source: The environment object to read from (defaults to process.env).
  • options:
    • strict (boolean): Warns about variables found in the source that aren't in the schema.
    • prefix (string): Filters and strips a specific prefix (like APP_) from variables.
    • onError: 'throw' (default), 'log', or 'silent'.

Schema Types

Available core types for coercion: string, number, integer, boolean, url, email, json, port.

Field Rule Properties

When defining fields as an object instead of a string, you have access to:

  • type: One of the types above.
  • required: If the variable must be present (defaults to true).
  • default: Fallback value if missing.
  • enum: Array of allowed values.
  • regex: Regular expression to match string values against.
  • min, max: Range boundaries for numeric values.
  • validate: Custom validation function (value) => boolean | string | void. Return string for custom error message.
  • description: Used in error messages and example generation.
  • example: Provide explicit sample value for auto-generated config.

generateExample(schema, [options])

Returns a string that you can write to a .env.example file.

check(schema, [source], [options])

CI-friendly helper that returns 0 if the environment is valid and 1 if invalid. Does not throw exceptions, but instead prints a formatted error report directly to the console.

License

MIT