{"id":15043899,"url":"https://github.com/dev-ashishk/nest-env-config","last_synced_at":"2025-04-14T23:12:43.280Z","repository":{"id":244702446,"uuid":"816000751","full_name":"dev-ashishk/nest-env-config","owner":"dev-ashishk","description":"The @nodeflip/nest-env-config module provides a convenient way to manage environment configuration in your NestJS applications. By using decorators, you can define configuration properties that are automatically populated from environment variables with optional default values. ","archived":false,"fork":false,"pushed_at":"2025-01-30T13:02:00.000Z","size":106,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T23:12:38.557Z","etag":null,"topics":["config","env","environment-variables","http","httpservice","nest-config","nestjs","nestjs-backend","nodeflip","nodejs","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@nodeflip/nest-env-config","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/dev-ashishk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-16T19:26:20.000Z","updated_at":"2025-01-30T13:02:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"0db3c847-69f5-4618-9abb-b7b65d474d8f","html_url":"https://github.com/dev-ashishk/nest-env-config","commit_stats":null,"previous_names":["nodeflip/nest-env-config","dev-ashishk/nest-env-config"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-env-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-env-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-env-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-env-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-ashishk","download_url":"https://codeload.github.com/dev-ashishk/nest-env-config/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975328,"owners_count":21192210,"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","environment-variables","http","httpservice","nest-config","nestjs","nestjs-backend","nodeflip","nodejs","typescript"],"created_at":"2024-09-24T20:49:47.948Z","updated_at":"2025-04-14T23:12:43.264Z","avatar_url":"https://github.com/dev-ashishk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![example workflow](https://github.com/nodeflip/nest-env-config/actions/workflows/test.yml/badge.svg)\n[![npm version](https://badge.fury.io/js/%40nodeflip%2Fnest-env-config.svg)](https://badge.fury.io/js/%40nodeflip%2Fnestjs-env-config)\n[![downloads](https://img.shields.io/npm/dm/@nodeflip/nest-env-config.svg)](https://www.npmjs.com/package/@nodeflip/nestjs-env-config)\n\n# 🚀 Nest Environment Configuration Module\n\n## Overview\n\nThe `@nodeflip/nest-env-config` module provides a convenient way to manage environment configuration in your NestJS applications. By using decorators, you can define configuration properties that are automatically populated from environment variables with optional default values. This module ensures that your configuration is strongly typed and easily accessible throughout your application.\n\n## Installation\n\nTo install the module, run the following command:\n\n```bash\nnpm install @nodeflip/nest-env-config\n```\n\n## How to use it ?\n### Setting Up the Module\nFirst, import the EnvironmentConfigModule in your application's module and call the forRoot method with your configuration class.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { EnvironmentConfigModule } from '@nodeflip/nest-env-config';\nimport { AppConfig } from './app-config';\nimport { DBConfig } from './db-config';\n\n@Module({\n  imports: [\n    EnvironmentConfigModule.forRoot({configClass: AppConfig}),\n    EnvironmentConfigModule.forRoot({configClass: DBConfig, serviceName: 'DB_CONFIG_SERVICE'})\n  ],\n})\nexport class AppModule {}\n```\n\n### Creating a Configuration Class\nDefine a configuration class and use the @Prop decorator to specify the environment variables and their default values.\n```typescript\nimport { Prop } from '@nodeflip/nest-env-config';\n\nexport class AppConfig {\n  @Prop('APP_PORT', 3000)\n  public port: number;\n\n  @Prop('APP_ENV', 'development')\n  public env: string;\n\n  @Prop('DATABASE_URL')\n  public databaseUrl: string;\n}\n```\n## Injecting the Configuration Service\nInject the EnvironmentConfigService into your services to access the configuration properties.\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { EnvironmentConfigService } from '@nodeflip/nest-env-config';\nimport { AppConfig } from './app-config';\nimport { DBConfig } from './db-config';\n\n@Injectable()\nexport class AppService {\n  constructor(\n    private readonly appConfigService: EnvironmentConfigService\u003cAppConfig\u003e,\n    @Inject('DB_CONFIG_SERVICE') private readonly dbConfigService: EnvironmentConfigService\u003cDBConfig\u003e\n  ) {\n    console.log(this.appConfigService.config);\n    console.log(this.dbConfigService.config);\n  }\n\n  getPort(): number {\n    return this.dbConfigService.config.port;\n  }\n}\n```\n\n## Testing\nThe EnvironmentConfigModule can be easily tested using the NestJS testing utilities. Below is an example of how to set up and test the configuration service.\n\n##### Example Test Configuration Class\n```typescript\nimport { Prop } from '@nodeflip/nest-env-config';\n\nexport class DBConfig {\n  @Prop('DB_NAME', 'test_db')\n  name: string;\n\n  @Prop('DB_USERNAME', 'test_user')\n  username: string;\n\n  @Prop('DB_PASSWORD', 'test_password')\n  password: string;\n\n  @Prop('DB_HOST', 'test_host')\n  host: string;\n\n  @Prop('DB_PORT', 5432)\n  port: number;\n\n  @Prop('ENABLE_LOGGING', false)\n  logging: boolean;\n}\n```\n##### Example Test Suite\n```typescript\nimport { Test, TestingModule } from '@nestjs/testing';\nimport { EnvironmentConfigModule } from '@nodeflip/nest-env-config';\nimport { EnvironmentConfigService } from '@nodeflip/nest-env-config';\nimport { DBConfig } from './db-config';\n\ndescribe('EnvironmentConfigService', () =\u003e {\n  let service: EnvironmentConfigService\u003cDBConfig\u003e;\n\n  beforeEach(async () =\u003e {\n    const module: TestingModule = await Test.createTestingModule({\n      imports: [EnvironmentConfigModule.forRoot({configClass: DBConfig})],\n    }).compile();\n\n    service = module.get\u003cEnvironmentConfigService\u003cDBConfig\u003e\u003e(EnvironmentConfigService);\n  });\n\n  it('should be defined', () =\u003e {\n    expect(service).toBeDefined();\n  });\n\n  it('should retrieve configuration properties', () =\u003e {\n    const config = service.config;\n    expect(config).toBeDefined();\n    expect(config.name).toBe('test_db');\n    expect(config.username).toBe('test_user');\n    expect(config.password).toBe('test_password');\n    expect(config.host).toBe('test_host');\n    expect(config.port).toBe(5432);\n    expect(config.logging).toBe(false);\n  });\n});\n```\n\n## Package Contents\n\nThe module includes the following main components:\n\n- **EnvironmentConfigModule**: The module to be imported into your application module.\n- **EnvironmentConfigService**: A service that provides access to the configuration properties.\n- **Prop Decorator**: A decorator for defining configuration properties.\n\n### EnvironmentConfigModule\n\nThe `EnvironmentConfigModule` is a dynamic module that registers the `EnvironmentConfigService` with the specified configuration class.\n\n### EnvironmentConfigService\n\nThe `EnvironmentConfigService` retrieves the configuration values from the environment variables and maps them to the properties defined in the configuration class.\n\n### Prop Decorator\n\nThe `Prop` decorator is used to define class properties that will be populated with values from the environment variables.\n\n## Contributing\n\nContributions are welcome! Please follow the standard GitHub workflow to contribute to this project.\n\n1. Fork the repository.\n2. Create a new branch.\n3. Make your changes.\n4. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Dependencies\n\n- `@nestjs/common`\n- `@nestjs/config`\n- `@nestjs/core`\n- `reflect-metadata`\n\nEnjoy using `@nodeflip/nest-env-config`!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-ashishk%2Fnest-env-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-ashishk%2Fnest-env-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-ashishk%2Fnest-env-config/lists"}