{"id":20609598,"url":"https://github.com/mateodelnorte/cconfig","last_synced_at":"2025-04-15T04:30:50.531Z","repository":{"id":16475364,"uuid":"19227631","full_name":"mateodelnorte/cconfig","owner":"mateodelnorte","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-26T18:50:22.000Z","size":137,"stargazers_count":3,"open_issues_count":13,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-13T16:33:17.435Z","etag":null,"topics":["cascading","config","config-management","configuration","environment-variables","javascript","node"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mateodelnorte.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2014-04-28T05:04:15.000Z","updated_at":"2024-05-07T21:34:19.711Z","dependencies_parsed_at":"2023-01-13T18:52:03.403Z","dependency_job_id":"52bcb62e-affb-4512-8d41-2b22f09d2dfb","html_url":"https://github.com/mateodelnorte/cconfig","commit_stats":{"total_commits":40,"total_committers":7,"mean_commits":5.714285714285714,"dds":0.775,"last_synced_commit":"c0bb66ac7d5f4a3b7e0e6c4da906fc1bc2c0faba"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateodelnorte%2Fcconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateodelnorte%2Fcconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateodelnorte%2Fcconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mateodelnorte%2Fcconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mateodelnorte","download_url":"https://codeload.github.com/mateodelnorte/cconfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249006329,"owners_count":21197251,"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":["cascading","config","config-management","configuration","environment-variables","javascript","node"],"created_at":"2024-11-16T10:14:00.835Z","updated_at":"2025-04-15T04:30:50.513Z","avatar_url":"https://github.com/mateodelnorte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mateodelnorte/cconfig.svg?branch=master)](https://travis-ci.org/mateodelnorte/cconfig)\n\n# cconfig\n\n`cconfig` is a simple cascading config system. It provides a simple, but easily overrideable, solution for environment specific application config. \n\ncconfig loads a `config.js` or `config.json` file from your `process.cwd()`. If it finds that object, it will look for a property in it matching `process.env.NODE_ENV` (if undefined, it will use `NODE_ENV=development`) and overwrite any environment-specific properties found there. Then, it will overwrite that object using `process.env`. \n\nWith `cconfig` you can define global and environment specific config values, and override them using command line level or system level environment variables. \n\n## Installation\n```\n    npm install cconfig\n```\n## Setup and usage\n```\n    NODE_ENV=development node myscript.js\n```\ncconfig uses the NODE_ENV env var to provide environmenet-specific configuration settings. Available settings include process environment variables provided to the process, as well as global and environment-specific settings specified in a config.json file. \n\n### config.js || config.json\n\ncconfig can be loaded to expect a `config.json` or `config.js` file in the process' base directory cwd: \n```\n    var config = require('cconfig')(); \n```\nor you may specify a config file location (this is useful when your application is running in a different directory than where the config.js/config.json resides): \n```\n    var config = require('cconfig')('./path/to/my/config.json'); \n    // ----- OR -----\n    var config = require('cconfig')('./path/to/my/config.js')\n``` \nalternatively, you may chose to provide an object as a base configuration\n```\n    var defaultConfig = { port: 1337 }\n    var config = require('cconfig')(defaultConfig)\n```\n\n### Cascading Overrides \n\nThe configuration provided through a file or object may include global values and values particular to any NODE_ENV environment name that may be specified. Global variables specified in config.json will override any process environment variable values, and environment-specific items in config.json will override default values defined there as well. \n```\n    {\n      \"MULTI_ENV_VAR\": \"this var will be used in all environments\",\n      \"OVERRIDEABLE_VAR\": \"this var will be used, unless overriden for another environment\",\n      \"development\": {\n        \"ANOTHER_VAR\": \"mongodb://somevalue:27017/somedb\"\n      },\n      \"staging\": {\n        \"ANOTHER_VAR\": \"mongodb://somevalue2:27017/somedb,\n        \"OVERRIDEABLE_VAR\": \"this var will be used for staging, unless overriden for another environment\",\n      },\n      \"production\": {\n        \"ANOTHER_VAR\": \"mongodb://somevalue3:27017/somedb,\n        \"OVERRIDEABLE_VAR\": \"this var will be used for production, unless overriden for another environment\",\n      }\n    }\n```    \n\nusage is simple:\n\nassuming `node myApp.js` or `NODE_ENV=development node myApp.js`:\n```\n    var config = require('cconfig')();\n    \n    console.log(config.NODE_ENV); // prints \"development\"\n    console.log(config.MULTI_ENV_VAR\"); // prints \"this var will be used in all environments\"\n    console.log(config.OVERRIDEABLE_VAR\"); // prints \"this var will be used, unless overriden for another environment\"\n    console.log(config.ANOTHER_VAR\"); // prints \"mongodb://somevalue:27017/somedb\"\n```\nassuming `NODE_ENV=staging node myApp.js`:\n```\n    var config = require('cconfig')();\n    \n    console.log(config.NODE_ENV); // prints \"staging\"\n    console.log(config.MULTI_ENV_VAR\"); // prints \"this var will be used in all environments\"\n    console.log(config.OVERRIDEABLE_VAR\"); // prints \"this var will be used, unless overriden for another environment\"\n    console.log(config.ANOTHER_VAR\"); // prints \"mongodb://somevalue2:27017/somedb\"\n```\nIndividual values can be overriden by environment variables specified globally or inline as well. \n\nassuming: `OVERRIDEABLE_VAR=\"text straight from the command line\" NODE_ENV=production node myApp.js`:\n```\n    var config = require('cconfig')();\n    \n    console.log(config.NODE_ENV); // prints \"production\"\n    console.log(config.MULTI_ENV_VAR\"); // prints \"this var will be used in all environments\"\n    console.log(config.OVERRIDEABLE_VAR\"); // text straight from the command line\"\n    console.log(config.ANOTHER_VAR\"); // prints \"mongodb://somevalue3:27017/somedb\"\n```\n\nIt's possible to override nested properties from the command line as well. Assuming a `config.js` file similar to the following:\n```\nmodule.exports = {\n    BROKER: {\n        HOST: 'localhost'\n        PORT: 1243\n    }\n}\n```\nThe `PORT` property can be overriden from the command line via: `\"BROKER.PORT\"=1235 node myApp.js`. If you're coding on Windows and want to be able to use similar behavior, see the very useful package [cross-env](https://www.npmjs.com/package/cross-env).\n\n# Run the tests\n```\n    npm test\n```\n[1]: https://www.npmjs.org/package/cconfig\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateodelnorte%2Fcconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmateodelnorte%2Fcconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateodelnorte%2Fcconfig/lists"}