Nest-Typed-Config is a robust and intuitive configuration module designed for the NestJS framework, providing a type-safe approach to managing application settings. Unlike other configuration solutions like the official `@nestjs/config` or `nestjs-config`, this library eliminates the need for manual type-casting by allowing developers to define their configuration schema using TypeScript classes and decorators, similar to DTOs. It supports various loaders including environment variables, JSON, YAML, TOML, and remote endpoints, and integrates seamlessly with `class-validator` and `class-transformer` for comprehensive configuration validation and transformation. The current stable version is `2.10.1`, with active development and frequent releases to support new NestJS versions and introduce features like environment variable overrides and default values for file loaders.
npm install nest-typed-configVerified import paths — ran on the pinned version, not inferred.
This quickstart defines a type-safe configuration schema, loads it from a YAML file using `fileLoader`, registers it with `TypedConfigModule`, and injects the fully typed configuration directly into a NestJS service.
Upgrade `nest-typed-config` to `v2.9.4` or higher for full NestJS v11 compatibility. Always check peer dependency requirements when updating NestJS.
Ensure `reflect-metadata` is installed (`npm i reflect-metadata`) and consider upgrading `nest-typed-config` to `v2.9.3` or newer to support `reflect-metadata@0.2.x` without conflicts. Remember to `import 'reflect-metadata';` at the entry point (e.g., `main.ts`).
To optimize dependency size and bootstrap time, refer to the `OPTIONAL-DEP.md` guide in the package's GitHub repository. You can manually install only the specific loader packages you need and configure `nest-typed-config` to skip default installations.
Upgrade to `nest-typed-config v2.10.1` or newer to resolve known Webpack bundling issues and ensure stable operation in bundled environments.
Upgrade to `v2.9.0` or higher to leverage default values and variable substitution in configuration files for `cosmic-config` loaders, and to `v2.10.0` for `dotenvLoader`.
Ensure the `schema` property points to a correctly imported TypeScript class, which should be decorated with `class-validator` and `class-transformer` decorators, and that `TypedConfigModule` can access it.
Review your configuration file (e.g., `.env.yaml`, `config.json`) and environment variables. Compare them against the type definitions and validation decorators (e.g., `@IsString()`, `@IsNumber()`, `@ValidateNested()`) in your `RootConfig` and nested classes.
Ensure you are using ES module `import { TypedConfigModule } from 'nest-typed-config';` syntax. If your project uses CommonJS, you might need to adjust your TypeScript configuration or build process to correctly handle module interop, or ensure `type: "module"` is set in your `package.json` for ESM projects.Verify that your configuration files exist at the specified `absolutePath` and that their format (e.g., YAML, JSON) is correct. Check loader options (e.g., `yaml: true`, `json: true`) and ensure environment variables are correctly set if using `dotenvLoader`.