{"id":13941173,"url":"https://github.com/andrewhayward/js-config-store","last_synced_at":"2025-10-18T14:18:10.656Z","repository":{"id":12314857,"uuid":"14949467","full_name":"andrewhayward/js-config-store","owner":"andrewhayward","description":"JavaScript config lookup","archived":false,"fork":false,"pushed_at":"2014-01-03T14:28:16.000Z","size":173,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-02T14:10:16.619Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrewhayward.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2013-12-05T09:37:46.000Z","updated_at":"2023-11-28T20:17:39.000Z","dependencies_parsed_at":"2022-08-29T00:40:54.244Z","dependency_job_id":null,"html_url":"https://github.com/andrewhayward/js-config-store","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhayward%2Fjs-config-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhayward%2Fjs-config-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhayward%2Fjs-config-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewhayward%2Fjs-config-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewhayward","download_url":"https://codeload.github.com/andrewhayward/js-config-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252894807,"owners_count":21821058,"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-08-08T02:01:13.087Z","updated_at":"2025-10-18T14:18:05.594Z","avatar_url":"https://github.com/andrewhayward.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Config Store\n\nA JavaScript config store.\n\nThe source is available for download from\n[GitHub](http://github.com/andrewhayward/js-config-store).\nAlternatively, you can install using Node Package Manager (npm):\n\n    npm install config-store\n\n## On the Server\n\nOn the server, it will read from three different locations (in order of priority):\n\n * command line arguments\n * a JSON configuration object (which may be read from a file)\n * environment variables\n\n### Usage:\n\n```javascript\nvar configStore = require('config-store');\nvar config = configStore({...});\n// or      = configStore('./config.json');\n\nvar port = config('PORT', 3000);\nvar host = config('HOST');\n```\n\nAlternatively:\n\n```javascript\nvar configStore = require('config-store');\nconfigStore({...}, function (err, config) {\n  var port = config('PORT', 3000);\n  var host = config('HOST');\n});\n```\n\n\n## In the Browser\n\nIn the browser, it will read from a JSON configuration object (which may be read from a file). So far it's not been tested - feel free to do so!\n\n### Usage:\n\n```html\n\u003cscript src=\"configStore.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  (function () {\n    var config = configStore({...});\n\n    var port = config('PORT', 3000);\n    var host = config('HOST');\n  })();\n\u003c/script\u003e\n\n\u003cscript\u003e\n  (function () {\n    configStore('/config.json', function (err, config) {\n      var port = config('PORT', 3000);\n      var host = config('HOST');\n    });\n  })();\n\u003c/script\u003e\n```\n\n## `find`\n\nSometimes, you might want to pull in entire sets of data from config...\n\n```javascript\n{\n  \"db\": {\n    \"host\": \"...\",\n    \"user\": \"...\",\n    \"password\": \"...\"\n  }\n}\n```\n\nThe standard `config` lookup doesn't handle this, as it maps this type of structure to `env`-style variables, so `config('db')` would not return anything.\n\nHowever, `config.find` is available for this type of situation, and lets you pull blocks of config out of the store. Unlike the standard lookup, it won't throw an error if the key is not found and you don't provide a fallback - the return value will just be `undefined`.\n\n```javascript\nvar db = config.find('db');\n// {host: \"...\", user: \"...\", password: \"...\"}\nvar user = config.find('db.user');\n// \"...\"\nvar port = config.find('db.port');\n// undefined\nvar port = config.find('db.port', 80);\n// 80\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewhayward%2Fjs-config-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewhayward%2Fjs-config-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewhayward%2Fjs-config-store/lists"}