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

dotenv-fast-checker

v0.1.1

Published

A program for validating and checking environment variables.

Readme

dotenv-fast-checker

npm version
GitHub license

A simple Node.js utility to validate environment variables' existence and type while using the dotenv package. This module ensures that your environment variables are both defined and of the expected type, making it easy to work with process.env safely.

Features

  • Check if an environment variable is defined.
  • 🔍 Validate the type of the environment variable (supports String, Number, Boolean).
  • 💨 Fast and lightweight: Simply integrates with dotenv.
  • 🛠️ Easy to use: Small API for quick validation setup.

Installation

Install the package via npm:

npm install dotenv-fast-checker

Usage

  1. Ensure that you have a .env file with your environment variables.

  2. Import the package in your code:

    import "dotenv/config"; // To load environment variables from .env
    import EnvChecker from "dotenv-fast-checker";
  3. Use the check method to validate and retrieve environment variables:

    // Example of checking an environment variable
    const myString = EnvChecker.check("MY_STRING_VAR", String);
    const myNumber = EnvChecker.check("MY_NUMBER_VAR", Number);
    const myBoolean = EnvChecker.check("MY_BOOLEAN_VAR", Boolean);
    • If the environment variable is not defined, an error will be thrown.
    • If the variable is defined but its type doesn't match the expected type, an error will be thrown.

Example with dotenv

import "dotenv/config";
import EnvChecker from "dotenv-fast-checker";

// Check environment variables with type validation
const port = EnvChecker.check("PORT", Number); // Expects a number
const isProduction = EnvChecker.check("IS_PRODUCTION", Boolean); // Expects a boolean
const apiUrl = EnvChecker.check("API_URL", String); // Expects a string

Type Checking

The check function validates the environment variable's type as follows:

  • String: Ensures the variable is a valid string.
  • Number: Ensures the variable is a valid number.
  • Boolean: Ensures the variable is one of the following valid boolean values:
    • 'true', 'false', 'True', 'False', '1', '0'

If an environment variable is not of the expected type, the package throws an error with a message indicating the invalid value and expected type.

API

EnvChecker.check(name: string, type?: StringConstructor | NumberConstructor | BooleanConstructor): string | number | boolean | undefined

  • name: The name of the environment variable.
  • type: The expected type (String, Number, Boolean). This argument is optional. If not provided, the function will return the environment variable value as a string.

Returns the environment variable value, parsed to the expected type (if valid), or throws an error if invalid.

GitHub Repository

You can find the source code and contribute to the project on GitHub: https://github.com/zaksiu12s/dotenv-fast-checker

License

MIT License. See the LICENSE file for details.