{"id":15097609,"url":"https://github.com/it-gorillaz/configify","last_synced_at":"2025-04-12T19:48:26.284Z","repository":{"id":217519568,"uuid":"743270720","full_name":"it-gorillaz/configify","owner":"it-gorillaz","description":"NestJS Config on Steroids","archived":false,"fork":false,"pushed_at":"2025-04-07T10:11:24.000Z","size":779,"stargazers_count":122,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T19:48:16.739Z","etag":null,"topics":["aws","configuration","nestjs","typescript"],"latest_commit_sha":null,"homepage":"https://buymeacoffee.com/tommelo","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/it-gorillaz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-14T20:41:51.000Z","updated_at":"2025-04-12T11:18:34.000Z","dependencies_parsed_at":"2024-03-30T23:05:14.913Z","dependency_job_id":"2df2a719-b751-40cf-b274-00f753d166e5","html_url":"https://github.com/it-gorillaz/configify","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.39473684210526316","last_synced_commit":"7708c787197cf07de32dc13ed3d6472a731fb1ad"},"previous_names":["it-gorillaz/configfy","it-gorillaz/configify"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it-gorillaz%2Fconfigify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it-gorillaz%2Fconfigify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it-gorillaz%2Fconfigify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/it-gorillaz%2Fconfigify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/it-gorillaz","download_url":"https://codeload.github.com/it-gorillaz/configify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625500,"owners_count":21135513,"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":["aws","configuration","nestjs","typescript"],"created_at":"2024-09-25T16:24:00.894Z","updated_at":"2025-04-12T19:48:26.254Z","avatar_url":"https://github.com/it-gorillaz.png","language":"TypeScript","funding_links":["https://buymeacoffee.com/tommelo"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo-small.svg\" width=\"200\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cb\u003e@itgorillaz/configify\u003c/b\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003eNestJS config on steroids\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://buymeacoffee.com/tommelo\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\n**configify** is a NestJS configuration module that makes it easier to deal with configuration files and secrets.\n\n## Installation\n\n```bash\n$ npm install --save @itgorillaz/configify\n```\n\n## Usage\n\nTo start using the \u003cb\u003econfigify\u003c/b\u003e module in your application import the module by calling the `forRootAsync` function:\n\n```js\n@Module({\n  imports: [ConfigifyModule.forRootAsync()],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\n**Important Note**: When working with strict mode enabled `\"strict\": true`(tsconfig.json) it's necessary to set the option `strictPropertyInitialization` to `false` since the module will initialize the configuration class properties during runtime after resolving the values of the environment variables.\n\nBy default, when bootstraping, the module will lookup for a `.env`, an `application.yml` and an `application.json` file at the root folder of the project:\n\n```\nmy-web-app\n| .env\n| application.yml\n| application.json\n```\n\nYou can also provide the location of the configuration files by overriding the configuration options.\n\n### Mapping Configuration Classes\n\nThis module will lookup for every class decorated with `@Configuration` and it will make its instance globally available for the application.\n\nExample of a `.env` file mapped to a class:\n\n```\nAPPLICATION_CLIENT_ID=ABC\nAPPLICATION_CLIENT_TOKEN=TEST\n```\n\n```js\n@Configuration()\nexport class ApplicationClientConfig {\n  @Value('APPLICATION_CLIENT_ID')\n  appClientId: string;\n\n  @Value('APPLICATION_CLIENT_TOKEN')\n  appClientToken: string\n}\n```\n\nExample of a `.yml` file mapped to a class:\n\n```\ndatabase:\n  host: localhost\n  port: 3306\n  username: test\n  password: test\n  metadata: |\n    {\n      \"label\": \"staging\"\n    }\n```\n\n```js\n@Configuration()\nexport class DatabaseConfiguration {\n  @Value('database.host')\n  host: string;\n\n  @Value('database.port', {\n    parse: parseInt\n  })\n  port: number;\n\n  @Value('database.metadata', {\n    parse: JSON.parse\n  })\n  metadata: MetadataType;\n}\n```\n\nYou can map your configuration file to multiple configuration classes:\n\n```\n# database config\nDATABASE_HOST=localhost\nDATABASE_USER=test\nDATABASE_PASSWORD=test\n\n# okta config\nOKTA_API_TOKEN=test\nOKTA_CLIENT_ID=test\n```\n\n```js\n@Configuration()\nexport class DatabaseConfiguration {\n  // database configuration attributes\n}\n```\n\n```js\n@Configuration()\nexport class OktaConfiguration {\n  // okta configuration attributes\n}\n```\n\n### Dependency Injection\n\nThis module makes all the configuration instances globally available to the application, to access it you just need to declare the configuration class as an argument in the class constructor:\n\n```js\nexport class AppService {\n  private readonly LOGGER = new Logger(AppService.name);\n\n  constructor(private readonly config: MyConfig) {\n    this.LOGGER.log(JSON.stringify(config));\n  }\n\n}\n```\n\n### Variables Expansion\n\nYou can make use of variable expansion in your configuration files:\n\n```\nMY_API_KEY=${MY_SECRET} // --\u003e MY_API_KEY=TEST\nANY_OTHER_CONFIG=TEST\nMY_SECRET=TEST\nAPP_CLIENT_ID=${NON_EXISTING_ENV:-DEFAULT_ID} // --\u003e APP_CLIENT_ID=DEFAULT_ID\n```\n\n### Defining Default Configuration Values\n\nOther than defining default values with variables expansion, you can also define a default value to an attribute using the `default` option provided by the `@Value()` decorator:\n\n```js\n@Configuration()\nexport class DatabaseConfiguration {\n  @Value('DB_HOST', { default: 'localhost' })\n  host: string;\n\n  @Value('DB_PORT', {\n    parse: parseInt,\n    default: 3306\n  })\n  port: number;\n}\n```\n\n### Dealing with Secrets\n\nOut of the box, this module can resolve secrets from:\n\n- AWS Secrets Manager and AWS Parameter Store\n- Azure Key Vault\n- Bitwarden Secrets Manager\n- Google Cloud Secret Manager\n- Custom Remote Configuration Resolver(your own implementation)\n\nCheck the [examples](/examples/) and their documentation to learn how to use them.\n\n### Parsing Configuration Values\n\nParsing a configuration value can be easily done by using a parse callback function available as argument of the `@Value()` decorator:\n\n```yaml\ndb-json-config: |\n  {\n    \"host\": \"localhost\",\n    \"user\": \"test\",\n    \"password\": \"test\"\n  }\n```\n\n```js\nexport interface MyDBConfig {\n  host: string;\n  user: string;\n  password: string;\n}\n\n@Configuration()\nexport class SuperSecretConfiguration {\n  @Value('db-json-config', {\n    parse: JSON.parse\n  })\n  myDbConfig: MyDBConfig;\n}\n```\n\n### Validating Configuration Classes\n\nDepending on how critical a configuration is, you may want to validate it before starting the application, for that you can use [class-validator](https://github.com/typestack/class-validator) to make sure your configuration is loaded correctly:\n\n```js\n@Configuration()\nexport class MyConfiguration {\n  @IsEmail()\n  @Value('SENDER_EMAIL')\n  senderEmail: string;\n\n  @IsNotEmpty()\n  @Value('my-api-token')\n  myApiToken: string;\n}\n```\n\n### Overwrite Default Options\n\nYou can overwrite default module options by providing an object as argument to the `forRootAsync()` method:\n\n```js\n/**\n* Ignores any config file.\n* The default value is false;\n*/\nignoreConfigFile?: boolean;\n\n/**\n* Ignores environment variables\n* The default value is false;\n*/\nignoreEnvVars?: boolean;\n\n/**\n* The path of the configuration files\n*/\nconfigFilePath?: string | string[];\n\n/**\n* Expands variables\n* The default value is true\n*/\nexpandConfig?: boolean;\n\n/**\n * The secrets resolvers strategies\n */\nsecretsResolverStrategies?: ConfigurationResolver[];\n```\n\n## License\n\nThis code is licensed under the [MIT License](./LICENSE.txt).\n\nAll files located in the node_modules and external directories are externally maintained libraries used by this software which have their own licenses; we recommend you read them, as their terms may differ from the terms in the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fit-gorillaz%2Fconfigify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fit-gorillaz%2Fconfigify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fit-gorillaz%2Fconfigify/lists"}