{"library":"nest-typed-config","title":"Nest Typed Config","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nest-typed-config"],"cli":null},"imports":["import { TypedConfigModule } from 'nest-typed-config'","import { ConfigService } from 'nest-typed-config'","import { fileLoader } from 'nest-typed-config'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Allow, ValidateNested, IsString, IsNumber } from 'class-validator';\nimport { Type } from 'class-transformer';\nimport { Module, Injectable } from '@nestjs/common';\nimport { TypedConfigModule, fileLoader } from 'nest-typed-config';\n\n// config.ts\nexport class TableConfig {\n  @IsString()\n  public readonly name!: string;\n}\n\nexport class DatabaseConfig {\n  @Type(() => TableConfig)\n  @ValidateNested()\n  public readonly table!: TableConfig;\n}\n\nexport class RootConfig {\n  @Type(() => DatabaseConfig)\n  @ValidateNested()\n  public readonly database!: DatabaseConfig;\n\n  @IsString()\n  public readonly appHost!: string;\n\n  @IsNumber()\n  public readonly appPort!: number;\n}\n\n// app.module.ts (assuming a config.yaml or .env.yaml exists in the root)\n// Example config.yaml:\n// database:\n//   table:\n//     name: myapp_main\n// appHost: localhost\n// appPort: 3000\n\n@Module({\n  imports: [\n    TypedConfigModule.forRoot({\n      schema: RootConfig,\n      load: fileLoader({\n        yaml: true,\n        absolutePath: process.cwd(),\n        ignoreEnvFile: false,\n      }),\n      isDevelopment: process.env.NODE_ENV !== 'production',\n      validate: true,\n    }),\n  ],\n})\nexport class AppModule {}\n\n// app.service.ts\n@Injectable()\nexport class AppService {\n  constructor(private readonly config: RootConfig) {}\n\n  getAppInfo(): string {\n    return `Application running at http://${this.config.appHost}:${this.config.appPort} with table: ${this.config.database.table.name}`;\n  }\n}\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}