{"id":26504712,"url":"https://github.com/codemask-labs/node-config","last_synced_at":"2026-03-13T09:01:19.878Z","repository":{"id":269008239,"uuid":"709890004","full_name":"codemask-labs/node-config","owner":"codemask-labs","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-01T01:32:47.000Z","size":2983,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-01T02:35:35.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemask-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-25T15:41:43.000Z","updated_at":"2025-11-19T08:27:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"18136669-383e-4a9c-a314-542a9a18d53d","html_url":"https://github.com/codemask-labs/node-config","commit_stats":null,"previous_names":["codemask-labs/nestjs-config","codemask-labs/node-config"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/codemask-labs/node-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemask-labs%2Fnode-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemask-labs%2Fnode-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemask-labs%2Fnode-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemask-labs%2Fnode-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemask-labs","download_url":"https://codeload.github.com/codemask-labs/node-config/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemask-labs%2Fnode-config/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30463545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T06:34:02.089Z","status":"ssl_error","status_checked_at":"2026-03-13T06:33:49.182Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-20T20:13:04.130Z","updated_at":"2026-03-13T09:01:19.824Z","avatar_url":"https://github.com/codemask-labs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Config\n\nA utility library designed to simplify configuration management in TypeScript and Node.js applications. This library includes powerful decorators, validation features, and utils to effortlessly integrate and validate application configurations.\n\n## Features\n\n### 1. Simplified Configuration Management\n- Define configurations as strongly typed classes with decorators for validation and transformation.\n- Centralize configuration logic, making it easy to maintain and extend.\n\n### 2. Type-Safe Configurations\n- The `getConfig` function ensures type safety by mapping environment variables directly to configuration class properties.\n- Automatically parses and validates properties against the defined class structure.\n\n### 3. Validation with `class-validator`\n- Use decorators like `@IsString`, `@IsEnum`, `@IsInt`, and `@IsBoolean` to enforce rules on configuration values.\n- Validation errors provide meaningful feedback during development or runtime.\n\n### 4. Dynamic Transformation with `class-transformer`\n- Apply transformations (e.g., converting strings to booleans) seamlessly using decorators like `@Transform`.\n\n### 5. Integration with Frameworks\n- Built to integrate easily with frameworks like [NestJS](https://nestjs.com), enabling configuration classes to power dynamic module setups (e.g., database connections).\n\n### 6. Environment Variable Handling\n- Map environment variables to class properties effortlessly.\n- Enforces clean and predictable configuration values from the environment.\n\n### 7. Dependency injection between config classes\n- Define constructor based injections, similiar to `Injectables` in Nestjs modules\n- Synchronized resolve of dependent configurations within one class\n\n### 8. Reads environment variables from .env files using dotenv\n- Out-of-the-box integration with [dotenv](https://github.com/motdotla/dotenv) library for reading environment variables\n\n### 9. Supports `DOTENV_CONFIG_PATH` environment variable\n- Switch or load dotenv environment from a different path\n\n## Installation\n\n### yarn\n\n```bash\nyarn add @codemask-labs/node-config class-validator class-transformer\n```\n\n### npm\n\n```bash\nnpm install @codemask-labs/node-config class-validator class-transformer\n```\n\n## API\n\n### getConfig\n\n```typescript\ndeclare function getConfig(configClass: ClassType): ConfigInstance\n```\n\nRetrieves and validates an instance of the configuration class.\n\n#### Parameters\n- configClass: The configuration class with `@Config` and validation decorators applied.\n\n#### Returns\n- An instance of the validated configuration class.\n\n### getConfigValue\n\n```typescript\ndeclare function getConfigValue\u003cT extends ClassType, U\u003e(configClass: T, getter: (config: T) =\u003e U): U\n```\n\nRetrieves and validates an instance of the configuration class, and passed through a `getter` to return a value.\n\n#### Parameters\n- configClass: The configuration class with `@Config` and validation decorators applied.\n- getter: The getter function that runs synchronously on\n\n#### Returns\n- An value constructed by  of the validated configuration class.\n\n### Env decorator\n\n```typescript\ndeclare function Env(propertyName: string): MethodDecorator\n```\n\nMaps process environment to class property by name, useful when you need to validate or transform environment variable and map it to other casing.\n\n#### Parameters\n- propertyName: The usually `process.env` key to a value\n\n#### Retruns\n- An class property decorator that can be used within a @Config decorated class.\n\n## Usage\n\n### Define a Configuration Class\nUse decorators to define and validate configuration properties.\n\n```typescript\nimport { Transform } from 'class-transformer';\nimport { IsBoolean, IsEnum, IsInt, IsString, MaxLength } from 'class-validator';\nimport { Config } from '@codemask-labs/node-config';\nimport { TypeormConnection } from 'example/enums';\n\n@Config()\nexport class TypeormConfig {\n    @IsEnum(TypeormConnection)\n    readonly TYPEORM_CONNECTION: TypeormConnection;\n\n    @IsString()\n    readonly TYPEORM_HOST: string;\n\n    @IsInt()\n    readonly TYPEORM_PORT: number;\n\n    @IsString()\n    readonly TYPEORM_DATABASE: string;\n\n    @IsString()\n    @MaxLength(100)\n    readonly TYPEORM_USERNAME: string;\n\n    @IsString()\n    readonly TYPEORM_PASSWORD: string;\n\n    @IsBoolean()\n    readonly TYPEORM_LOGGING: boolean;\n\n    @IsBoolean()\n    @Transform(({ value }) =\u003e value === 'true')\n    readonly TYPEORM_DEBUG: boolean;\n}\n\n```\n\n### Access Configuration in Code\n\nUse the `getConfig` function to access and validate the configuration class.\n\n```typescript\nimport { getConfig } from '@codemask-labs/node-config';\nimport { TypeormConfig } from 'example/config';\n\nconst config = getConfig(TypeormConfig);\n\nconsole.log(config.TYPEORM_HOST); // Outputs the validated host value\n```\n\n### Example Integration with NestJS\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { TypeOrmModule } from '@nestjs/typeorm';\nimport { getConfig } from '@codemask-labs/node-config';\nimport { TypeormConfig } from 'example/config';\n\n@Module({\n    imports: [\n        TypeOrmModule.forRootAsync({\n            useFactory: () =\u003e {\n                const {\n                    TYPEORM_CONNECTION,\n                    TYPEORM_HOST,\n                    TYPEORM_PORT,\n                    TYPEORM_USERNAME,\n                    TYPEORM_PASSWORD,\n                    TYPEORM_DATABASE,\n                    TYPEORM_LOGGING,\n                } = getConfig(TypeormConfig);\n\n                return {\n                    type: TYPEORM_CONNECTION,\n                    host: TYPEORM_HOST,\n                    port: TYPEORM_PORT,\n                    username: TYPEORM_USERNAME,\n                    password: TYPEORM_PASSWORD,\n                    database: TYPEORM_DATABASE,\n                    entities: Object.values({}),\n                    migrations: Object.values({}),\n                    synchronize: false,\n                    migrationsRun: true,\n                    autoLoadEntities: true,\n                    logging: TYPEORM_LOGGING ? 'all' : undefined,\n                };\n            },\n        }),\n    ],\n})\nexport class UsersModule {}\n```\n\n### Injecting other configurations to a single class\n\n```typescript\nimport { NodeEnv } from 'example/enums';\n\nexport class NodeConfig {\n    @IsEnum(NodeEnv)\n    @Env('NODE_ENV') // reads it from `process.env`, and maps it to your class property `environment`\n    readonly environment: NodeEnv;\n}\n```\n\n```typescript\nimport { NodeConfig } from 'example/config';\n\nexport class TypeormConfig {\n    constructor(readonly nodeConfig: NodeConfig) {}\n}\n```\n\n```typescript\nimport { TypeormConfig } from 'example/config';\n\nconst config = getConfig(TypeormConfig); // Transforms and validates `NodeConfig` as dependency, then transforms and validates `TypeormConfig`, returns instance.\n\nconsole.log(config.nodeConfig.environment); // Outputs the validated and transformed value of `NODE_ENV`\n\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemask-labs%2Fnode-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemask-labs%2Fnode-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemask-labs%2Fnode-config/lists"}