{"id":16326690,"url":"https://github.com/chrisyip/node-easyconfig","last_synced_at":"2025-08-13T19:36:38.978Z","repository":{"id":57218826,"uuid":"84863095","full_name":"chrisyip/node-easyconfig","owner":"chrisyip","description":"Easy configuration for node.js","archived":false,"fork":false,"pushed_at":"2019-01-24T07:33:41.000Z","size":76,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T22:12:17.242Z","etag":null,"topics":["nodejs","nodejs-modules"],"latest_commit_sha":null,"homepage":null,"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/chrisyip.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":"2017-03-13T18:53:33.000Z","updated_at":"2017-04-19T08:54:45.000Z","dependencies_parsed_at":"2022-08-28T23:20:17.264Z","dependency_job_id":null,"html_url":"https://github.com/chrisyip/node-easyconfig","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chrisyip/node-easyconfig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fnode-easyconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fnode-easyconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fnode-easyconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fnode-easyconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisyip","download_url":"https://codeload.github.com/chrisyip/node-easyconfig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisyip%2Fnode-easyconfig/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265528865,"owners_count":23782771,"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":["nodejs","nodejs-modules"],"created_at":"2024-10-10T23:09:18.652Z","updated_at":"2025-07-16T18:04:10.427Z","avatar_url":"https://github.com/chrisyip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EasyConfig\n\n[![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Travis CI][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url]\n\nEasy configuration for node.js\n\n## Install\n\n```\nnpm i easyconfig\n```\n\n## Quick start\n\nExample file structure:\n\n```\nAPP_ROOT\n├── config\n│   ├── default.js\n│   ├── development.json\n│   └── production.js\n└── index.js\n```\n\n`default.js`:\n\n```js\nmodule.exports = {\n  get assetPrefix () {\n    return `${this.cdn}/assets`\n  }\n}\n```\n\n`development.json`:\n\n```json\n{\n  \"cdn\": \"http://localhost\"\n}\n```\n\n`production.js`:\n\n```js\nmodule.exports = {\n  cdn: 'https://cdn.domain.com'\n}\n```\n\n`index.js`:\n\n```js\nconst EasyConfig = require('easyconfig')\nconsole.log(EasyConfig().assetPrefix)\n```\n\n```\nnode index.js\n// print \"http://localhost/assets\"\n\nNODE_ENV=production node index.js\n// print \"https://cdn.domain.com/assets\"\n```\n\n## Usage\n\n### Where config file stores\n\nBy default, it's `${process.cwd()}/config`.\n\n### Loading config with `NODE_ENV`\n\n`easyconfig` will try to load config file that matches `NODE_ENV`.\n\n```\nNODE_ENV=production node app.js\n```\n\n```js\nconst config = EasyConfig() // returns config/production.js\n```\n\n- If `NODE_ENV` is empty, will use `development`.\n- If none of files matches `NODE_ENV`, will return data in `default` file or an empty object.\n\n### Loading config by name\n\n```js\nconst config = EasyConfig('development')\nconst specialConfig = EasyConfig('specialConfig')\n```\n\n### Loading config outside `config/`\n\n```js\nconst config = EasyConfig({ basedir: 'path/to/config/file' })\n// Or\nconst config = EasyConfig({\n  basedir: 'path/to/config/file',\n  name: 'config name'\n})\n```\n\n### Loading config non-js file\n\nYou can use `easyconfig.register` to load non-js file.\n\n`easyconfig.register(EXTNAME, FILE_LOADER)`\n\nFor example, `cson`:\n\n```js\nconst cson = require('cson')\nconst EasyConfig = require('easyconfig')\nEasyConfig.register('.cson', cson.load.bind(cson))\n```\n\n### Default config file\n\n`easyconfig` will search for `default` file and merge it into target config file.\n\n### Property descriptors\n\n`easyconfig` respects property descriptor, so you can do things like this:\n\nIn `default.js`:\n\n```js\nmodule.exports = {\n  get foo () {\n    return `${this.bar}/${this.baz}`\n  }\n}\n```\n\nIn other files:\n\n```js\nmodule.exports = {\n  bar: 'bar',\n  baz: 'baz'\n}\n```\n\n```js\nconst config = EasyConfig()\nconsole.log(config.foo) // bar/baz\n```\n\n[npm-url]: https://npmjs.org/package/easyconfig\n[npm-image]: http://img.shields.io/npm/v/easyconfig.svg\n[daviddm-url]: https://david-dm.org/chrisyip/node-easyconfig\n[daviddm-image]: http://img.shields.io/david/chrisyip/node-easyconfig.svg\n[travis-url]: https://travis-ci.org/chrisyip/node-easyconfig\n[travis-image]: http://img.shields.io/travis/chrisyip/node-easyconfig.svg\n[codecov-url]: https://codecov.io/gh/chrisyip/node-easyconfig\n[codecov-image]: https://img.shields.io/codecov/c/github/chrisyip/node-easyconfig.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fnode-easyconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisyip%2Fnode-easyconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisyip%2Fnode-easyconfig/lists"}