Skip to main content

NanoForge


npm versionnpm downloadsTests statusLast commitContributors

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.

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:
Then validate and populate an instance from a raw environment object with registerEnv:
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.

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.

Classes

Functions