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-manager-grootbit

v1.0.4

Published

A TypeScript-based module to manage environment variables with schema validation.

Readme

Env Manager - Grootbit

Env Manager is a utility to manage and validate environment variables in your projects. It ensures your environment variables are correctly set up, reducing runtime errors caused by missing or invalid variables.


Features

  • Schema-based Validation: Define required variables and their types in a schema.
  • Type Conversion: Automatically converts strings to integer, float, boolean, or retains as string.
  • Singleton Pattern: Ensures a single instance of the manager is used throughout the project.
  • Error Handling: Alerts on missing or incorrectly formatted variables.
  • Environment Cleanup: Clears loaded environment variables from process.env after validation.

Installation

Install the package via npm:

npm install env-manager-grootbit

Or using yarn:

yarn add env-manager-grootbit

Usage

To use Env Manager, define a schema for your environment variables, initialize the manager using the Singleton pattern, and access validated variables across your project.

Example

  1. Create a Schema
    Define a schema with the expected variables, their types, and whether they are required.
import { EnvManager, EnvType } from "env-manager-grootbit";

const schema = {
  AWS_ACCESS_KEY: { type: EnvType.STRING, required: true },
  AWS_SECRET_KEY: { type: EnvType.STRING, required: true },
  PORT: { type: EnvType.INTEGER, required: false },
  DEBUG_MODE: { type: EnvType.BOOLEAN, required: false },
};

EnvManager.init(schema);

try {
  const envs = EnvManager.envys;
  console.log("Validated Environment Variables:", envs);
} catch (error) {
  console.error("Environment validation failed:", error.message);
  process.exit(1);
}
  1. Access the Singleton Instance
    Once initialized, the EnvManager provides access to validated environment variables via the static envys property.
const envs = EnvManager.envys;
console.log(envs.PORT); // Access validated variables safely
  1. Run Your Project
    Set environment variables in your .env file or directly in your system’s environment. Example:
AWS_ACCESS_KEY=your-access-key
AWS_SECRET_KEY=your-secret-key
PORT=3000
DEBUG_MODE=true

Run the application:

npm start

Key Concepts

Singleton Pattern

The EnvManager now uses the Singleton pattern to ensure that a single instance of the manager is used throughout your project. You initialize the manager once with the init method and access the validated environment variables via the static envys property.

Schema Definition

The schema is an object where each key represents an environment variable. Each variable has the following properties:

  • type: The expected data type (EnvType.STRING, EnvType.INTEGER, EnvType.FLOAT, or EnvType.BOOLEAN).
  • required: Boolean indicating whether the variable is mandatory.

Supported Types

| Type | Description | |---------------|----------------------------------------| | EnvType.STRING | Standard string values. | | EnvType.INTEGER | Numeric values, parsed as integers. | | EnvType.FLOAT | Numeric values, parsed as floats. | | EnvType.BOOLEAN | true or false values. |

Environment Variable Cleanup

After validation, all environment variables defined in the schema are removed from process.env to prevent accidental access. Access them only through the envys property of the EnvManager class.


Error Handling

  • Missing Variables: Throws an error if required variables are missing.
  • Type Mismatch: Throws an error if a variable’s value does not match the defined type.
  • Extra Variables: Logs a warning if additional variables are detected that are not defined in the schema.

Example Log:

Warning: Extra environment variables detected: UNSUPPORTED_KEY

Development Notes

This module integrates into your project as a library. Include it in your main entry file, define the schema, and initialize the EnvManager class. The validation process is triggered automatically when accessing the envys property.


Changelog

v1.0.3

  • Introduced the Singleton pattern to ensure a single instance of EnvManager.
  • Added the static envys property for simplified access to validated variables.
  • Enhanced error handling and logging for extra environment variables.

License

This project is licensed under the MIT License.