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

@nanoforge-dev/env

v2.0.0

Published

NanoForge Engine - Env

Readme

About

@nanoforge-dev/env is a wrapper around class-validator and class-transformer used to validate and transform raw environment values (InitContext.env, process.env, …) into typed, decorated configuration classes.

Installation

Node.js 26 or newer is required.

npm install @nanoforge-dev/env
yarn add @nanoforge-dev/env
pnpm add @nanoforge-dev/env
bun add @nanoforge-dev/env

Warning

This library is intended for use by other NanoForge libraries and application code that reads environment configuration — it is not a library that consumers of @nanoforge-dev/core need to install standalone unless they are declaring their own environment-backed config classes.

Example usage

Declare a configuration class decorated with @nanoforge-dev/env's decorators:

import {
  Default,
  Expose,
  IsBoolean,
  IsByteLength,
  IsIpOrURL,
  IsOptional,
  IsPort,
  TransformToBoolean,
} from "@nanoforge-dev/env";

export class ClientConfigNetwork {
  // Optional port, but must be a valid port string when present.
  @Expose()
  @IsOptional()
  @IsPort()
  SERVER_TCP_PORT?: string;

  // Required — must be a valid IP address or URL.
  @Expose()
  @IsIpOrURL(undefined, undefined, { protocols: ["ws", "wss", "http", "https"] })
  SERVER_ADDRESS!: string;

  // Falls back to "PACKET_END" when absent.
  @Expose()
  @Default("PACKET_END")
  @IsByteLength(2, 64)
  MAGIC_VALUE!: string;

  // "true"/"false" string values are transformed into a native boolean.
  @Expose()
  @TransformToBoolean()
  @IsBoolean()
  @Default(false)
  WSS!: boolean;
}

Then validate and populate an instance from a raw environment object with registerEnv:

import { registerEnv } from "@nanoforge-dev/env";

import { ClientConfigNetwork } from "./config.client.network";

export class NetworkClientLibrary extends Library {
  public override async __init(ctx: InitContext): Promise<void> {
    const config = await registerEnv(ClientConfigNetwork, ctx.env);

    // `config` is a fully validated, defaulted ClientConfigNetwork instance.
  }
}

registerEnv throws NfEnvValidationException when the given environment doesn't satisfy the class's decorators.

All of class-validator's decorators (IsString, IsPort, IsOptional, …) and class-transformer's @Expose/@Transform are re-exported directly from this package, alongside @nanoforge-dev/env's own additions:

  • @Default(value) — supplies a fallback when the property is undefined/null.
  • @IsIpOrURL(...) — validates an IPv4/IPv6 address or a fully qualified domain name.
  • @TransformToBoolean() — transforms the string "true"/"false" into a native boolean.

Links

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the documentation.
See the contribution guide if you'd like to submit a PR.

Help

If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in discussions.