{"id":17230075,"url":"https://github.com/robinbuschmann/type-config","last_synced_at":"2025-06-14T07:38:56.519Z","repository":{"id":57383189,"uuid":"134147838","full_name":"RobinBuschmann/type-config","owner":"RobinBuschmann","description":" Type safe way defining configurations fed by environment variables, process arguments or json config files (including deserialization and validation)","archived":false,"fork":false,"pushed_at":"2018-06-13T16:12:47.000Z","size":155,"stargazers_count":13,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T15:52:34.726Z","etag":null,"topics":["config","env","json","type-safety"],"latest_commit_sha":null,"homepage":"","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/RobinBuschmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-20T12:17:23.000Z","updated_at":"2024-10-28T14:42:12.000Z","dependencies_parsed_at":"2022-09-13T23:23:06.322Z","dependency_job_id":null,"html_url":"https://github.com/RobinBuschmann/type-config","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Ftype-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Ftype-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Ftype-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Ftype-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinBuschmann","download_url":"https://codeload.github.com/RobinBuschmann/type-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809044,"owners_count":21164895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["config","env","json","type-safety"],"created_at":"2024-10-15T04:52:22.123Z","updated_at":"2025-04-14T01:42:26.672Z","avatar_url":"https://github.com/RobinBuschmann.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/RobinBuschmann/type-config.svg?branch=master)](https://travis-ci.org/RobinBuschmann/type-config)\n[![codecov](https://codecov.io/gh/RobinBuschmann/type-config/branch/master/graph/badge.svg)](https://codecov.io/gh/RobinBuschmann/type-config)\n\n# type-env\nType safe way defining configurations fed by environment variables, process arguments or json config files \n(including deserialization and validation).\n\n## Installation\n```bash\nnpm install type-env --save\n```\n*type-env* requires [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)\n```\nnpm install reflect-metadata --save\n```\nYour `tsconfig.json` needs the following flags:\n```json\n{\n  \"experimentalDecorators\": true,\n  \"emitDecoratorMetadata\": true\n}\n```\n\n## Getting started\n#### Setup configuration class\n```typescript\nimport {Config, EnvValue} from 'type-env';\n@Config\nclass DataBaseConfiguration {\n    @EnvValue('DB_HOST') host: string = 'localhost'; // default value\n    @EnvValue('DB_NAME') name: string;\n    @EnvValue('DB_PORT') port: number;\n}\n```\n```typescript\nimport {Config, ArgsValue} from 'type-env';\n@Config\nclass LoggingConfiguration {\n    @ArgsValue('log-level') level: string;\n    @ArgsValue('silent') silent: boolean;\n}\n```\n```json\n{\n  \"auth\": {\n    \"jwt\": {\n      \"issuer\": \"type-env\"\n    },\n    \"timestamp\": \"2018-05-27T17:35:54.391Z\"\n  }\n}\n```\n```typescript\nimport {Config, JsonConfiguration, JsonValue} from 'type-env';\n@Config\n@JsonConfiguration(`${__dirname}/config.json`)\nclass AuthConfiguration {\n    @JsonValue('auth.jwt.issuer') jwtIssuer: string = 'type-env';\n    @JsonValue('auth.timestamp') timestamp: Date;\n}\n```\n#### Run application\n```bash\nDB_HOST='127.0.0.1' /\nDB_NAME='type-env' /\nDB_PORT='1234' /\nnode app.js --log-level info --silent\n```\n\n## Options\n```typescript\nimport {buildDecorators, NodeEnvConfigSource, NodeArgsConfigSource, JsonConfigSource} from 'type-env';\n\nconst {Value, EnvValue, ArgsValue, JsonValue} = buildDecorators({\n    /**\n     * Enables validation if true. Throws if config value is invalid.\n     * @default true\n     */\n    validate: true,\n    \n    /**\n     * Throws if value does not exist on source.\n     * @default true\n     */\n    required: true,\n    \n    /**\n     * If true, loads config value when property is accessed.\n     * @default true\n     */\n    lazyLoad: true,\n\n    /**\n     * Do not throw on validation or requirement errors, but logs a warning instead.\n     * @default false\n     */\n    warnOnly: false,\n    \n    /**\n     * Map of decorator key name and config source.\n     * @default {\n                    Value: NodeEnvConfigSource,\n                    EnvValue: NodeEnvConfigSource,\n                    ArgsValue: NodeArgsConfigSource,\n                    JsonValue: JsonConfigSource,\n                }\n     */\n    decoratorMeta: {\n        Value: NodeEnvConfigSource,\n        EnvValue: NodeEnvConfigSource,\n        ArgsValue: NodeArgsConfigSource,\n        JsonValue: JsonConfigSource,\n    }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Ftype-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinbuschmann%2Ftype-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Ftype-config/lists"}