{"id":21662492,"url":"https://github.com/constantiner/resolve-node-configs-hierarchy","last_synced_at":"2026-05-18T00:33:12.323Z","repository":{"id":33153840,"uuid":"152262691","full_name":"Constantiner/resolve-node-configs-hierarchy","owner":"Constantiner","description":"Fight configuration headaches for different environments without pain","archived":false,"fork":false,"pushed_at":"2023-01-06T01:36:12.000Z","size":3537,"stargazers_count":1,"open_issues_count":32,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-09T12:06:10.421Z","etag":null,"topics":["configuration","configuration-files","configuration-management","dotenv","env","environment","environment-variables","hierarchical-configuration","javascript","library","nodejs"],"latest_commit_sha":null,"homepage":"https://constantiner.github.io/resolve-node-configs-hierarchy/","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/Constantiner.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":"2018-10-09T14:10:50.000Z","updated_at":"2020-04-21T14:42:34.000Z","dependencies_parsed_at":"2023-01-14T23:42:03.938Z","dependency_job_id":null,"html_url":"https://github.com/Constantiner/resolve-node-configs-hierarchy","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/Constantiner/resolve-node-configs-hierarchy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantiner%2Fresolve-node-configs-hierarchy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantiner%2Fresolve-node-configs-hierarchy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantiner%2Fresolve-node-configs-hierarchy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantiner%2Fresolve-node-configs-hierarchy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Constantiner","download_url":"https://codeload.github.com/Constantiner/resolve-node-configs-hierarchy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Constantiner%2Fresolve-node-configs-hierarchy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264455988,"owners_count":23611065,"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":["configuration","configuration-files","configuration-management","dotenv","env","environment","environment-variables","hierarchical-configuration","javascript","library","nodejs"],"created_at":"2024-11-25T10:16:27.493Z","updated_at":"2026-05-18T00:33:07.291Z","avatar_url":"https://github.com/Constantiner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resolve-node-configs-hierarchy\u003c!-- omit in toc --\u003e\n\n[![Build Status](https://travis-ci.org/Constantiner/resolve-node-configs-hierarchy.svg?branch=master)](https://travis-ci.org/Constantiner/resolve-node-configs-hierarchy) [![codecov](https://codecov.io/gh/Constantiner/resolve-node-configs-hierarchy/branch/master/graph/badge.svg)](https://codecov.io/gh/Constantiner/resolve-node-configs-hierarchy)\n\nSimple library to resolve configuration files hierarchy in Node projects for producing effective configuration from them.\n\nIt is very convenient if you need to have local configuration for local environment and not place it in version control system. Or to have separate configurations for `development` or `test` or `production` environments to apply them automatically.\n\nSo the library allows to manage configurations for any environment and the same code base.\n\n**Note** Don't forget to put `local` files to `.gitignore`.\n\n- [Changelog](#changelog)\n- [Documentation](#documentation)\n\t- [getConfigFiles](#getconfigfiles)\n\t- [getConfigFile](#getconfigfile)\n\t- [getConfigFilesSync](#getconfigfilessync)\n\t- [getConfigFileSync](#getconfigfilesync)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## Changelog\n\nVersions [changelog](docs/CHANGELOG.md).\n\n## Documentation\n\nSee the full documentation [here](https://constantiner.github.io/resolve-node-configs-hierarchy/).\n\nThe utility was inspired by [create-react-app](https://github.com/facebook/create-react-app) and may contain some chunks of code from it.\n\n**Note** To use in Node environment, not in browser.\n\nThe base idea is [the following](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use):\n\nIt will list the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence:\n\n* `.env` - The Original®\n* `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.\n* `.env.local` - Local overrides. This file is loaded for all environments except test (you can include it with flag as the second parameter).\n* `.env.development.local`, `.env.test.local` (for `test` environment you can include it with flag as the second parameter), `.env.production.local` - Local overrides of environment-specific settings.\n\nIt uses `process.env.NODE_ENV` for setting environment.\n\nFor test environment it will not list `.env.local` and `.env.test.local` from this list by default since normally you expect tests to produce the same results for everyone. You can include them by passing the second parameter with `true` value.\n\nIt may use any relative path as the base path even with extension.\n\nIt contains the following methods:\n\n### getConfigFiles\n\nReturns a list of absolute file paths of existing files in the order to apply from first to last (in order of precedence).\n\nfor example if you pass `\"configuration/log4js.json\"` it will produce the following list for development environment (if all of these files are exist in file system):\n\n* `\u003cproject_path\u003e/configuration/log4js.development.local.json`\n* `\u003cproject_path\u003e/configuration/log4js.local.json`\n* `\u003cproject_path\u003e/configuration/log4js.development.json`\n* `\u003cproject_path\u003e/configuration/log4js.json`\n\nThis utility is asynchronous and returns a promise resolving to file list. Use [`getConfigFilesSync`](#getconfigfilessync) for synchronous version.\n\nThis utility was inspired by [create-react-app](https://github.com/facebook/create-react-app) and may contain some chunks of code from it.\n\n**Note** The bundle contains only ES6 modules version. Use Babel, Rollup, Webpack etc. to produce commonjs version.\n\n### getConfigFile\n\nReturns the most relevant absolute file path of existing files in files hierarchy.\n\nfor example if you pass `\"configuration/log4js.json\"` it will return the following file path for development environment (if it exists in file system):\n\n* `\u003cproject_path\u003e/configuration/log4js.development.local.json`\n\nThis utility is asynchronous and returns a promise resolving to absolute file path as `String` (or resolving to `null`). Use [`getConfigFileSync`](#getconfigfilesync) for synchronous version.\n\n### getConfigFilesSync\n\nSynchronous version of [`getConfigFiles`](#getconfigfiles).\n\n### getConfigFileSync\n\nSynchronous version of [`getConfigFile`](#getconfigfile).\n\n## Installation\n\n```bash\nnpm install @constantiner/resolve-node-configs-hierarchy\n```\n\n## Usage\n\nImport it first:\n\n```JavaScript\nimport { getConfigFiles } from \"@constantiner/resolve-node-configs-hierarchy\";\n```\n\nThen you can use it:\n\n```JavaScript\ngetConfigFiles(\"src/.env\").then(files =\u003e {\n\tfiles.forEach(file =\u003e {\n\t\tdotenv.config({\n\t\t\tpath: file\n\t\t})\n\t})\n});\n```\n\nOr for getting the single most actual config file:\n\n```JavaScript\nimport { getConfigFile } from \"@constantiner/resolve-node-configs-hierarchy\";\n\ngetConfigFile(\"src/.env\").then(filePath =\u003e {\n\tif (filePath) {\n\t\tconst config = require(filePath);\n\t}\n});\n\n```\n\nTo include `local` files in `test` environment you may pass corresponding flag (it is `false` by default):\n\n```JavaScript\ngetConfigFiles(\"src/.env\", true).then(files =\u003e {\n\tfiles.forEach(file =\u003e {\n\t\tdotenv.config({\n\t\t\tpath: file\n\t\t})\n\t})\n});\n```\n\nOr the same for `getConfigFile`:\n\n```JavaScript\ngetConfigFile(\"src/.env\", true).then(filePath =\u003e {\n\tif (filePath) {\n\t\tconst config = require(filePath);\n\t}\n});\n```\n\nThe same is for synchronous versions:\n\n```JavaScript\nimport { getConfigFilesSync } from \"@constantiner/resolve-node-configs-hierarchy\";\n```\n\nThen you can use it:\n\n```JavaScript\ngetConfigFilesSync(\"src/.env\").forEach(file =\u003e {\n\tdotenv.config({\n\t\tpath: file\n\t})\n});\n```\n\nOr for getting the single most actual config file:\n\n```JavaScript\nimport { getConfigFileSync } from \"@constantiner/resolve-node-configs-hierarchy\";\n\nconst filePath = getConfigFileSync(\"src/.env\");\nif (filePath) {\n\tconst config = require(filePath);\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstantiner%2Fresolve-node-configs-hierarchy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconstantiner%2Fresolve-node-configs-hierarchy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstantiner%2Fresolve-node-configs-hierarchy/lists"}