{"id":27379457,"url":"https://github.com/nestcrafts/nestjs-easyconfig","last_synced_at":"2025-04-13T13:49:56.901Z","repository":{"id":35102082,"uuid":"206608127","full_name":"NestCrafts/nestjs-easyconfig","owner":"NestCrafts","description":"Manage nestjs configs on the go 🔥","archived":false,"fork":false,"pushed_at":"2024-05-19T11:15:14.000Z","size":3445,"stargazers_count":186,"open_issues_count":2,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T09:42:11.095Z","etag":null,"topics":["backend","configuration-management","hacktoberfest","nestjs","nestjs-easyconfig"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NestCrafts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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},"funding":{"github":["rubiin"],"patreon":null,"open_collective":"nestjs-easyconfig","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://www.buymeacoffee.com/XbgWxt567"]}},"created_at":"2019-09-05T16:21:20.000Z","updated_at":"2025-04-07T15:03:52.000Z","dependencies_parsed_at":"2024-05-16T16:29:23.506Z","dependency_job_id":"e338cb22-63d2-43bf-86c9-a417a1b7db2e","html_url":"https://github.com/NestCrafts/nestjs-easyconfig","commit_stats":null,"previous_names":["nestcrafts/nestjs-easyconfig","rubiin/nestjs-easyconfig"],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestCrafts%2Fnestjs-easyconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestCrafts%2Fnestjs-easyconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestCrafts%2Fnestjs-easyconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NestCrafts%2Fnestjs-easyconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NestCrafts","download_url":"https://codeload.github.com/NestCrafts/nestjs-easyconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724594,"owners_count":21151559,"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":["backend","configuration-management","hacktoberfest","nestjs","nestjs-easyconfig"],"created_at":"2025-04-13T13:49:56.373Z","updated_at":"2025-04-13T13:49:56.879Z","avatar_url":"https://github.com/NestCrafts.png","language":"TypeScript","funding_links":["https://github.com/sponsors/rubiin","https://opencollective.com/nestjs-easyconfig","https://www.buymeacoffee.com/XbgWxt567"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"left\"\u003e\n  \u003ca href=\"http://github.com/rubiin/nest-easyconfigs/\" target=\"blank\"\u003e\u003cimg src=\"https://i.imgur.com/BvxL0JR.png\" width=\"320\" height=\"200\" alt=\"\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n \u003cp float=\"left\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/nestjs-easyconfig\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/nestjs-easyconfig\" alt=\"Package License\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/nestjs-easyconfig\"\u003e\u003cimg src=\"https://img.shields.io/npm/dw/nestjs-easyconfig\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n \u003ca href=\"https://www.npmjs.com/package/nestjs-pgpromise\"\u003e\u003cimg src=\"https://github.com/rubiin/nestjs-easyconfig/actions/workflows/github-ci.yml/badge.svg\" alt=\"CI\" /\u003e\u003c/a\u003e \n\n\u003c/p\u003e\n \n## Description\n\n[Nestjs-easyconfig](https://github.com/rubiin/nestjs-easyconfig) loads configs from your `.env` (Wraps dotenv module) ⚙️ 🔥\n\n## Installation\n\n```bash\n$ npm install nestjs-easyconfig\n$ yarn add nestjs-easyconfig\n```\n\n## Usage\n\n### With config file supplied (basic):\n\n```javascript\nimport { Module } from '@nestjs/common';\nimport { EasyconfigModule } from 'nestjs-easyconfig';\n\n@Module({\n  imports: [EasyconfigModule.register({ path: './config/.env' })],\n})\nexport class AppModule {}\n```\n\n### With config file supplied and safe set to true:\n\n```javascript\nimport { Module } from '@nestjs/common';\nimport { EasyconfigModule } from 'nestjs-easyconfig';\n\n@Module({\n  imports: [EasyconfigModule.register({ path: './config/.env', safe: true })],\n})\nexport class AppModule {}\n```\n\nBy default safe is set to false. When safe is set to `true`, the module compares the supplied env\nfile with the sample env file to find missing keys. If any keys which are in .env.sample but not in the evironment used, it is immediately reported in console.\n\n`Note`: To use this, a sample env file `.env.sample` should be placed in the root dir\n\n\nOther config include dotenv's configs like encoding (Default: utf8) and debug(Default: false)\n\n### Without config file supplied:\n\n```javascript\nimport { Module } from '@nestjs/common';\nimport { EasyconfigModule } from 'nestjs-easyconfig';\n\n@Module({\n  imports: [EasyconfigModule.register({})],\n})\nexport class AppModule {}\n```\n\nIn this case, you have to pass in the \u003cb\u003eNODE_ENV\u003c/b\u003e value and the `.env` file to read will be determined accordingly.\nLoads environment variables from `.env.[development|test|production][.local]` files\nFor example, \u003cb\u003eNODE_ENV=dev\u003c/b\u003e will make the app read `.env.dev`\n\n\u003e Note: The .env file also has to be in root folder\n\n### Getting environment variables\n\nRegardless of how the `EasyconfigModule` is imported into the app, you can get the variable values using the `EasyconfigService`.\n\n```javascript\nimport { Controller, Get } from '@nestjs/common';\nimport { EasyconfigService } from 'nestjs-easyconfig';\n\n@Controller('api')\nexport class AppController {\n  constructor (private config: EasyconfigService) {}\n  @Get()\n  findAll() {\n    return {\n      value: this.config.get('key')\n    };\n  }\n}\n```\n\n\u003e Note: the `get` method will automatically cast environment variables\n\n### Type processing\nExample of type processing:\nImagine you have a configuration file at `.env` with the following:\n\n```bash\nFOO=bar\nBAZ=2\nBEEP=false\nBOOP=some,thing,that,goes,wow\n# note how we use an asterisk here to turn off the parsing for this variable\nBLEEP=false*\n# note how we use an asterisk in the array to turn off parsing for an array key value\nPING=ping,true*,2,100\n# note a string between bacticks won't be parsed\nPONG=`some,thing,that,goes,wow`\n```\n\nAfter using this plugin, the environment variables are parsed to their proper types.\n\nTo test it out, simply log the returned object in your console:\n\n```js\nconsole.log(env);\n```\n\nAnd you'll see that it outputs the properly parsed variable types:\n\n```js\n{\n  // String\n  FOO: 'bar',\n  // Number\n  BAZ: 2,\n  // Boolean\n  BEEP: false,\n  // Array\n  BOOP: [ 'some', 'thing', 'that', 'goes', 'wow' ],\n  // NOTE: this was not parsed due to the * asterisk override above\n  BLEEP: 'false',\n  // NOTE: only the `true*` above was opted out through the use of an asterisk\n  PING: [ 'ping', 'true', 2, 100 ],\n  // NOTE: this was not parsed because the string was between bacticks\n  PONG: 'some,thing,that,goes,wow'\n}\n```\n\nIf your configuration line ends in `*` it will not be parsed by this package, which allows you to keep values as the `String` variable type if needed. Also when you encapsulate a value between bacticks e.g. \\`value\\`, the value won't be parsed and it will return as a `String` variable. This can be used in situations where you for example have a ',' inside your string and it should not be parsed as an array.\n\n\n## Config\n\n```js\n    /**\n     * path to the file to load.\n     * If this is not passed, Easyconfig load the environment file based on\n     * the NODE_ENV with the naming convention of `.env.\u003cNODE_ENV\u003e`.\n     *\n     * For example, if the NODE_ENV is `production`, the file `.env.\u003cNODE_ENV\u003e` will load.\n     */\n    path ? : string;\n\n    /**\n     * path of the file to check the keys against when safe option is set to true.\n     * Defaults to .env.sample\n     */\n\n    sampleFilePath ? : string;\n\n    /**\n     * checks whether the used env file is missing some keys.\n     *\n     * For example, if the given `.env` file has the following content:\n     * ```\n     * VAR=true\n     * ```\n     *\n     * and the `.env.sample` file has the following:\n     * ```\n     * VAR=true\n     * VAR2=sample value\n     * ```\n     *\n     * the following error log will be printed:\n     * ```\n     * MissingEnvVarsError: [VAR2] were defined in .env.example but are not present in the environment:\n     *     This may cause the app to misbehave.\n     * ```\n     */\n    safe ? : boolean;\n\n    /**\n     * As the lib uses dotenv, You may turn on dotenv's logging to help debug why certain keys or\n     * values are not being set as you expect.\n     *\n     * default : false\n     */\n\n    debug ? : boolean;\n\n    /**\n     * This turns on parse logs which help debug how keys are being parsed.\n     *\n     * default : false\n     */\n\n    parseLog ? : boolean;\n\n    /**\n     * This option lets you specify the encoding of your file containing environment variables.\n     *\n     * ```\n     */\n\n    encoding ? : string;\n\n    /**\n     * This option allows you to pass in a pre-defined logger instance.\n     * The logger must implement the NestJS LoggerService interface\n     */\n\n    logger ? : LoggerService;\n\n    /**\n     * This option allows you assign the values to process.env . Defaults to true\n     */\n\n    assignToProcessEnv ? : boolean;\n\n    /**\n     * This option allows you overide a value on process.env if its alreadt set . Defaults to false\n     */\n\n    overrideProcessEnv ? : boolean;\n\n```\n\n## Contributing\n\nIn general, we follow the \"fork-and-pull\" Git workflow.\n\n1. Fork the repo on GitHub\n2. Clone the project to your own machine\n3. Work on your fork\n    1. Make your changes and additions\n        - Most of your changes should be focused on `src/` and `test/` folders and/or `README.md`. \n        - Files in `dist/` folder are autogenerated when running tests (`npm run build`) and need not to be changed **manually**. \n    2. Change or add tests if needed\n    3. Run tests and make sure they pass\n    4. Add changes to README.md if needed\n4. Commit changes to your own branch\n5. **Make sure** you merge the latest from \"upstream\" and resolve conflicts if there is any\n6. Repeat step 3(3) above\n7. git add and run npm run commit and fill in the details accordingly\n8. Push your work back up to your fork\n9. Submit a Pull request so that we can review your changes\n\n## Stay in touch\n\n- Author - [Rubin Bhandari](https://github.com/rubiin)\n- Dev․to - [@rubiin](https://dev.to/rubiin)\n- Discord - [@rubin#1186](https://discordapp.com/)\n\n## License\n\nThe package is [MIT licensed](LICENSE).\n\n## Support on Beerpay\n\nHey dude! Help me out for a couple of :beers:!\n\n[![Beerpay](https://beerpay.io/rubiin/nestjs-easyconfig/badge.svg?style=beer-square)](https://beerpay.io/rubiin/nestjs-easyconfig) [![Beerpay](https://beerpay.io/rubiin/nestjs-easyconfig/make-wish.svg?style=flat-square)](https://beerpay.io/rubiin/nestjs-easyconfig?focus=wish)\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/dlukanin\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/875405?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDmitry Lukanin\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-dlukanin\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=dlukanin\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=dlukanin\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/bradtaniguchi\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/10079147?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBrad\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-bradtaniguchi\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=bradtaniguchi\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://coollabs.io\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/5845193?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAndras Bacsai\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-andrasbacsai\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://www.eugenistoc.com\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/928780?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eEugen Istoc\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=genu\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=genu\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/jmcdo29\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/28268680?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJay McDoniel\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=jmcdo29\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=jmcdo29\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/byteglory\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/72143629?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRubin shrestha\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-byteglory\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=byteglory\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=byteglory\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/Aavash\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/16209762?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAavash Khatri\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-Aavash\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=Aavash\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/rubiin/nestjs-easyconfig/commits?author=Aavash\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestcrafts%2Fnestjs-easyconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnestcrafts%2Fnestjs-easyconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestcrafts%2Fnestjs-easyconfig/lists"}