{"id":30261665,"url":"https://github.com/peerigon/dynamic-config","last_synced_at":"2025-08-15T20:55:29.416Z","repository":{"id":15813492,"uuid":"18553110","full_name":"peerigon/dynamic-config","owner":"peerigon","description":"Loads configuration files depending on the given env","archived":false,"fork":false,"pushed_at":"2017-03-02T13:52:48.000Z","size":47,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-02T22:41:35.901Z","etag":null,"topics":["argv","configuration","env","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/peerigon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-04-08T09:44:57.000Z","updated_at":"2021-05-20T06:42:11.000Z","dependencies_parsed_at":"2022-08-25T15:02:15.306Z","dependency_job_id":null,"html_url":"https://github.com/peerigon/dynamic-config","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/peerigon/dynamic-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Fdynamic-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Fdynamic-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Fdynamic-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Fdynamic-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peerigon","download_url":"https://codeload.github.com/peerigon/dynamic-config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peerigon%2Fdynamic-config/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268505781,"owners_count":24260966,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["argv","configuration","env","javascript"],"created_at":"2025-08-15T20:55:23.498Z","updated_at":"2025-08-15T20:55:29.411Z","avatar_url":"https://github.com/peerigon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"dynamic-config\n==============\n**Dynamic configuration files**\n\n[![](https://img.shields.io/npm/v/dynamic-config.svg)](https://www.npmjs.com/package/dynamic-config)\n[![](https://img.shields.io/npm/dm/dynamic-config.svg)](https://www.npmjs.com/package/dynamic-config)\n[![Dependency Status](https://david-dm.org/peerigon/dynamic-config.svg)](https://david-dm.org/peerigon/dynamic-config)\n[![Build Status](https://travis-ci.org/peerigon/dynamic-config.svg?branch=master)](https://travis-ci.org/peerigon/dynamic-config)\n[![Coverage Status](https://img.shields.io/coveralls/peerigon/dynamic-config.svg)](https://coveralls.io/r/peerigon/dynamic-config?branch=master)\n\nLoads configuration files depending on:\n\n  - argv: `node app.js --env production`\n  - env: `export NODE_ENV=production; node app.js`\n\nExpects a `.js` file as config so you can add dynamic content.\n\n## Installation\n\n```\nnpm install dynamic-config --save\n```\n\n## Options\n\n### defaultEnv: string = *\"develop\"*\n\nDefine which env should be set as default.\n\n### log: Function\n\nCalls this function to log information about the path/env resolution.\n\n### envName: string = *\"env\"*\n\nThe argument/env variable name we expect.\n\n## Example\n\n```javascript\n// config/index.js\n\nconst DynamicConfig = require(\"dynamic-config\");\nconst dynamicConfig = new DynamicConfig({\n    defaultEnv: \"develop\",\n    log: console.log\n});\n\nmodule.exports = dynamicConfig.load(__dirname, \"config.js\");\n```\n\n```javascript\n// config/develop/config.js\n\nmodule.exports = {\n    whereami: \"develop\"\n}\n```\n\n```javascript\n// app.js\nconst config = require(\"./config\");\n\nconsole.log(config);\n```\n\n```javascript\nnode app.js\n\n{ whereami: 'develop' }\n\n// Set environment via args\nnode app.js --env prod\n\n{ whereami: 'prod' }\n\n// Set environment via env\nexport env=stage; node app.js\n\n{ whereami: 'stage' }\n```\n\n\n\n\n\n## Plugins\n\n### extend\n\nThese plugins allow you to override specific config fields by applying them via env, argv or a separate local config file.\n\n```javascript\nconst dynamicConfig = new (require(\"dynamic-config\"))();\n\n// extend from env\ndynamicConfig.use(require(\"dynamic-config/plugins/extend/env\"));\n\n// extend from file\ndynamicConfig.use(require(\"dynamic-config/plugins/extend/file\"));\n\n// extend from argv\ndynamicConfig.use(require(\"dynamic-config/plugins/extend/argv\"));\n\nmodule.exports = dynamicConfig.load(__dirname, \"config.js\");\n```\n\n**Hint:** The order in which the plugins are applied is important. In the above code snippet, config fields defined via arguments would override their counterparts from an override file, which itself overrides fields from environment variables. This is probably a suitable order for most projects.\n\n```javascript\nnode app.js\n\n{ name: 'superApp', port: 9000 }\n\n// Overwrite via argv\nnode app.js --port 80\n// ... or ...\nnode app.js --port=80\n\n{ name: 'superApp', port: 80 }\n\n// Overwrite via env\nexport port=90 node app.js\n\n{ name: 'superApp', port: 90 }\n\n// Order matters...\nexport port=90; node app.js --port 80\n\n{ name: 'superApp', port: 80 }\n```\n\n#### Extend via file\nCreate a file named the same as your config, but contains `.local` in front of the extension, like `config.js` becomes `config.local.js`.\n\nIn the config extension file you can define any subset of the object, that is defined in the main config and it would overwrite the corresponding value. Both configs are merged via [deep-assign](https://github.com/sindresorhus/deep-assign).\n\n```javascript\n// config.js\nmodule.exports = {\n    a: 1,\n    b: {\n        c: \"c\",\n        d: 2\n    },\n    e: 3\n}\n\n// config.local.js\nmodule.exports = {\n    e: \"e\",\n    b: {\n        d: \"d\"\n    }\n}\n\n// result\n{\n    a: 1,\n    b: {\n        c: \"c\",\n        d: \"d\"\n    },\n    e: \"e\"\n}\n```\n\n## Sponsors\n\n[\u003cimg src=\"https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png\" width=\"150\" /\u003e](https://peerigon.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerigon%2Fdynamic-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeerigon%2Fdynamic-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeerigon%2Fdynamic-config/lists"}