# @blueprod/config

> This module allows you to manage your application configurations in all popular ways:

Latest version **0.2.8** (published 2019-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blueprod/config
pnpm add @blueprod/config
yarn add @blueprod/config
bun add @blueprod/config
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.8 |
| Published | 2019-09-27 |
| First published | 2019-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thanh LE |
| Maintainers | thanhlq, vudv |

## Links

- npm: https://www.npmjs.com/package/@blueprod/config
- Repository: https://github.com/EMSA-TECHNOLOGY/blueprod
- Homepage: https://github.com/EMSA-TECHNOLOGY/blueprod/tree/master/packages/config#readme
- Issues: https://github.com/EMSA-TECHNOLOGY/blueprod/issues
- npm.io page: https://npm.io/package/@blueprod/config

## Dependencies (6)

- [glob](https://npm.io/package/glob.md) ^7.1.4
- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [dotenv](https://npm.io/package/dotenv.md) ^8.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.14
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.1
- [app-root-path](https://npm.io/package/app-root-path.md) ^2.2.1

## Recent versions

- 0.2.8 (latest) — 2019-09-27
- 0.2.4 — 2019-07-16
- 0.2.3 — 2019-07-16
- 0.2.2 — 2019-07-12

## README

# blueprod-config

This module allows you to manage your application configurations in popular ways:

- (Recommended) Twelve-Factor App: with one main **.env** and __.env.{{process.NODE_ENV}}__ for example: .env.test, .env.production, .env.development (https://github.com/motdotla/dotenv)
- But, our existing software is often dependent on the two other common formats: json & yaml, so we also support:
    - All file with [*.yaml (.json)] -> will be merged regardless to the duplication.
    - And maybe one of the following (if the file name matches with process.env.NODE_ENV): production.yaml (.json), test.yaml (.json) development.yaml (.json)

## Default App Structure

```
(Example for production)
rootAppPath:
   | config (supported to load recursively)
   |   |- default.yaml
   |   |- default.json
   |   |- production.yaml
   |
   |- .env
   |- .env.${NODE_ENV}
```

## How To Use

### Root application path

You have several options to provide the root application path or it will be detected

- config.load({rootAppPath: '/home/xxx')
- global.rootAppPath
- or process.env["BLUEPROD_ROOT_APP_PATH"]
- or we will use  the node module "app-root-path"

```javascript
const config = require('blueprod-config').load();
let configValue = config.get('app_key1')
```

## Options

You can put these parameters in .env or function arguments.

* CONFIG_DIR_NAME: the config folder name (i.e. config)
* ROOT_CONFIG_PATH: The root application configuration path. If this param is provided then CONFIG_DIR_NAME shall be ignored. 

## Merge Rules

```javascript
({}, { a: 'a' }, { a: 'bb' })         // => { a: "bb" }
({}, { a: 'a'  }, { a: undefined })   // => { a: "a" }
({}, { a: 'a'  }, { a: null })        // => { a: null }
({}, {a:{a:'a'}}, {a:{b:'bb'}})       // => { "a": { "a": "a", "b": "bb" }}
({}, {a:['a']}, {a:['bb']})           // => { "a": [ "bb" ] }

a={a:'a'}; merge(a, {b:'bb'});        // a => { a: "a", b: "bb" }
([], ['a'], ['bb'])                   // => [ "bb" ]
([], ['a','b'], ['bb'])               // => [ "bb", "b" ]
```

## License

MIT license 

## Author

Developed & maintained by EMSA TECHNOLOGY COMPANY LTD (contact @ emsa-technology dot com).

---
_Source: https://npm.io/package/@blueprod/config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
