# boldr-config

> A config loader for Boldr

Latest version **0.1.4** (published 2017-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install boldr-config
pnpm add boldr-config
yarn add boldr-config
bun add boldr-config
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2017-04-24 |
| First published | 2017-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Steven Truesdell |
| Maintainers | strues |
| Keywords | config, configuration, boldr |

## Links

- npm: https://www.npmjs.com/package/boldr-config
- Repository: https://github.com/boldr/boldr-tools
- Homepage: https://github.com/boldr/boldr-tools#readme
- Issues: https://github.com/boldr/boldr-tools/issues
- npm.io page: https://npm.io/package/boldr-config

## Dependencies (4)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [json5](https://npm.io/package/json5.md) ^0.5.1
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.8.3
- [cli-table2](https://npm.io/package/cli-table2.md) ^0.2.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2017-04-24
- 0.1.3 — 2017-04-24
- 0.1.2 — 2017-04-24
- 0.1.1 — 2017-04-24
- 0.1.0 — 2017-04-21

## README

# boldr-config

Boldr Config is a tool for configuring your JavaScript applications. Sharing similarities, yet expanding upon the shortfalls of other configuration tools.

Configuration values can be loaded from argv flags, environment variables, JSON config files, and YAML files.  



### Files and Loading Priority
Boldr Config crawls multiple paths searching for configuration files. Once found, the values are merged based on a hierarchy (explained below), placed into a single object, and loaded into your application.

1. argv flags passed through the command line.
`--db--host value` translates to `config.db.host === 'value'`
2. Environment variables
defined as `MY_APP__DB__HOST_NAME=value` translates to `config.db.hostName === 'value'`
**Anything below can be json5 or yaml** (requires installing js-yaml)
3. ~/.appNamerc
4. ~/.appName/config  
5. ~/.config/appName
6. ~/.config/appName/config
7. /etc/appNamerc
8. /etc/appName/config
9. /usr/local/etc/appNamerc
10. /usr/local/etc/appName/config
11. ./.appNamerc
12. ../.appNamerc
13. ../../.appNamerc
14. ...


## Usage

Create a new instance of BoldrConfig, pass it your application name 'boldr' followed by an object containing keys and values for your application. This is the default config.

```JavaScript
### config.js
import BoldrConfig from 'boldr-config';
//                   new instance   'name', keys/values
const boldrConfig = new BoldrConfig('boldr', {
  server: {
    port: 2121,
    host: '127.0.0.1',
    apiPrefix: '/api/v1',
    siteUrl: 'http://localhost:3000',
  },
  logging: {
    level: 'debug',
    file: {
      enable: true,
      dir: 'logs',
      level: 'info',
      filename: 'boldr.api',
    },
  },
  db: {
    url: 'postgres://postgres:password@127.0.0.1:5432/boldr',
    name: 'boldr',
    debug: false,
  },
  redis: {
    url: 'redis://127.0.0.1:6379/0',
  },
  token: {
    secret: 'v3ryS3cretT0k3n',
  },
  mail: {
    host: 'smtp.example.com',
    port: 465,
    ssl: true,
    user: 'email@email.com',
    password: 'password',
    from: 'email@email.com',
  },
  cors: {
    whitelist: ['http://localhost:2121', 'http://localhost:3000'],
  },
});

// create a constant config and tell your instance of boldrConfig to transform it to an object. Export config or whatever you called it and you can then import it anywhere in your app and retrieve values as normal.
// ex: const db = config.db.name
const config = boldrConfig.toObject();

export default config;

// What is this? See below on how you can use it.
export { boldrConfig };
```


## Display Config
It's possible to print out your configuration to stdout. When the configuration is printed, the source where the value was loaded from is also displayed.

To take advantage of this feature, call the `displayConfig()` method on your BoldrConfig instance.

```JavaScript
...^
import BoldrConfig from 'boldr-config';
const boldrConfig = new BoldrConfig('boldr', { ... });
const config = boldrConfig.toObject();
export { boldrConfig };

## server.js
import config, { boldrConfig } from './config';

console.log(boldrConfig.displayConfig());
```

Executing the displayConfig method will print what you see below to stdout.

```
  Displaying config for boldr
┌───────────────────────┬─────────────────────────────────────────────┬
│ Path                  │ Value                                             │ Source      │
│ server.port           │ 2121                                              │ .boldrrc    │
│ server.host           │ "127.0.0.1"                                       │ .boldrrc    │
│ server.apiPrefix      │ "/api/v1"                                         │ defaults    │
│ server.siteUrl        │ "http://localhost:3000"                           │ defaults    │
│ logging.level         │ "debug"                                           │ .boldrrc    │
│ logging.file.enable   │ true                                              │ defaults    │
│ db.debug              │ false                                             │ defaults    │
│ redis.url             │ "redis://redis:6379/0"                            │ environment │
└──────────────────┴───────────────────────────────────────────────────┴
```

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