{"id":18519220,"url":"https://github.com/alaricode/nestjs-dotenv","last_synced_at":"2025-04-09T08:32:06.879Z","repository":{"id":57310123,"uuid":"200006690","full_name":"AlariCode/nestjs-dotenv","owner":"AlariCode","description":"NestJS .env package allows you easily use .env file to store your app configs.","archived":false,"fork":false,"pushed_at":"2021-08-11T07:42:25.000Z","size":306,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T04:04:42.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://alariblog.ru/","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/AlariCode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-01T08:08:10.000Z","updated_at":"2023-01-27T01:52:48.000Z","dependencies_parsed_at":"2022-09-04T17:01:15.005Z","dependency_job_id":null,"html_url":"https://github.com/AlariCode/nestjs-dotenv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlariCode%2Fnestjs-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlariCode%2Fnestjs-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlariCode%2Fnestjs-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlariCode%2Fnestjs-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlariCode","download_url":"https://codeload.github.com/AlariCode/nestjs-dotenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248003289,"owners_count":21031763,"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":[],"created_at":"2024-11-06T17:15:43.362Z","updated_at":"2025-04-09T08:32:06.439Z","avatar_url":"https://github.com/AlariCode.png","language":"TypeScript","readme":"# NestJS .env config Module\n\n![alt cover](https://github.com/AlariCode/nestjs-dotenv/raw/master/img/logo.jpg)\n\n**More NestJS libs on [alariblog.ru](https://alariblog.ru)**\n\n[![npm version](https://badgen.net/npm/v/nestjs-dotenv)](https://www.npmjs.com/package/nestjs-dotenv)\n[![npm version](https://badgen.net/npm/license/nestjs-dotenv)](https://www.npmjs.com/package/nestjs-dotenv)\n[![npm version](https://badgen.net/github/open-issues/AlariCode/nestjs-dotenv)](https://github.com/AlariCode/nestjs-dotenv/issues)\n[![npm version](https://badgen.net/github/prs/AlariCode/nestjs-dotenv)](https://github.com/AlariCode/nestjs-dotenv/pulls)\n\nNestJS .env package allows you easily use .env file to store your app configs.\n\n```bash\nnpm i nestjs-dotenv\n```\n\nThen register module in your root app.module\n\n```javascript\nimport { ConfigModule } from 'nestjs-dotenv';\n\n@Module({\n\timports: [\n\t\t// ...\n\t\tConfigModule.forRoot(),\n\t],\n})\nexport class AppModule {}\n```\n\nIt will load `.env` file from your project root. If you need to change it's path just pass it to `forRoot` method like this:\n\n```javascript\nConfigModule.forRoot(myPath);\n```\n\nTo use ConfigService in any service or controller just inject it with `@ConfigInjection` decorator in the constructor:\n\n```javascript\nimport { ConfigService } from 'nestjs-dotenv';\n\nconstructor(\n\tprivate readonly configService: ConfigService\n) {}\n```\n\n## Get env value\n\nTo get a value from .env file just call `get()` method:\n\n```javascript\nthis.configService.get('JIRA_TOKEN');\n```\n\n-   JIRA_TOKEN - name of your key in `.env` file:\n\n```\nJIRA_TOKEN=0000000000000\n```\n\nMethod returns `string`.\n\n## Get env value and convert it to specific type\n\nInstead of `get()` method use `getWithType()`:\n\n```javascript\nthis.configService.getWithType('JIRA_TOKEN', 'string');\n```\n`getWithType()` get 3 parameters:\n-   name of your key in `.env` file.\n-   type of your data in `.env` file.\n-   (optional) Enum to convert data to, if your type is 'enum'.\n\nAvailable types:\n```bash\n// 'number'\nVALUE=1\n\n// 'string'\nVALUE=mystring\n\n// 'boolean'\nVALUE=true\n\n// 'array'\nVALUE=[1,2,3]\n\n// 'object'\nVALUE={\"key\": \"value\"}\n\n/** 'enum'\n enum Color {\n    White = 1\n    Black = 2\n} **/\nVALUE=White\n```\n\n## Reloading file\n\nTo reload env dynamically use `reload()` method:\n\n```javascript\nthis.configService.reload();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaricode%2Fnestjs-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falaricode%2Fnestjs-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaricode%2Fnestjs-dotenv/lists"}