# rduk-configuration

> Manage configuration in your Node.js app

Latest version **1.2.0** (published 2017-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install rduk-configuration
pnpm add rduk-configuration
yarn add rduk-configuration
bun add rduk-configuration
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2017-11-18 |
| First published | 2016-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+18 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kim UNG |
| Maintainers | khuang |
| Keywords | configuration, manager |

## Links

- npm: https://www.npmjs.com/package/rduk-configuration
- Repository: https://github.com/rd-uk/rduk-configuration
- Homepage: https://github.com/rd-uk/rduk-configurationr#readme
- Issues: https://github.com/rd-uk/rduk-configuration/issues
- npm.io page: https://npm.io/package/rduk-configuration

## Dependencies (4)

- [extend](https://npm.io/package/extend.md) 3.0.1
- [lodash](https://npm.io/package/lodash.md) 4.17.3
- [js-yaml](https://npm.io/package/js-yaml.md) 3.8.3
- [rduk-errors](https://npm.io/package/rduk-errors.md) 1.2.3

## 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

- 1.2.0 (latest) — 2017-11-18
- 1.1.0 — 2017-11-12
- 1.0.4 — 2017-10-20
- 1.0.3 — 2017-10-20
- 1.0.2 — 2017-10-06
- 1.0.1 — 2017-10-06
- 1.0.0 — 2017-09-22
- 0.1.2 — 2016-11-28
- 0.1.1 — 2016-10-29

## README

# RDUK - configuration

Manage your Node.js app configuration

[![Build Status](https://travis-ci.org/rd-uk/rduk-configuration.svg?branch=master)](https://travis-ci.org/rd-uk/rduk-configuration)
[![Coverage Status](https://coveralls.io/repos/github/rd-uk/rduk-configuration/badge.svg?branch=master)](https://coveralls.io/github/rd-uk/rduk-configuration?branch=master)

## Installation

```
npm install rduk-configuration --save --save-exact
```

## Naming

Add the configuration file at the root of your project.
You have to name it according to the argument passed to the factory.

```js
var configuration = require('rduk-configuration');

var myConfig;

/* config.yml */
myConfig = configuration();

/* config.dev.yml */
myConfig = configuration('dev');

/* config.prod.yml */
myConfig = configuration('prod');
```

__Note:__

If you set `NODE_ENV`, you can access the configuration according to it

```js
myConfig = configuration.load(); //will load config.dev.yml if NODE_ENV === dev
```

__Note:__

If you prefer put your config file within another folder, you can do so by adding 
in the `package.json` of your solution a rduk configuration section.

```json
# example of package.json
{
    ...
    "rduk": {
        "config": {
            "path": "path/to/config"
        }
    }
}
```
___

# Reference

* [Configuration](#configuration)
    * [.settings](#configuration.settings)
    * [.connections](#configuration.connections)
    * [.getSection(name, type)](#configuration.get_section)

<a name="configuration"></a>
## Configuration

<a name="configuration.settings"></a>
### Configuration.settings
Get the SettingsSection of the config file

yaml:

```yml
settings:
    facebook:
        appId: APP_ID
        appSecret: APP_SECRET
```

usage:

```js
var fbSettings = myConfig.settings.get('facebook');

console.log(fbSettings.appId); //will output APP_ID
console.log(fbSettings.appSecret); //will output APP_SECRET
```

<a name="configuration.connections"></a>
### Configuration.connections
Get the ConnectionsSection of the config file

yaml:

```yml
connections:
    -
        name: con1
        host: localhost
        user: db1_user
        password: 123456
        database: db1
    -
        name: con2
        host: localhost
        user: db2_user
        password: 123456
        database: db2
    -
        name: mapbox
        token: my_mapbox_token
    -
        name: gmap
        token: my_gmap_token
```

usage:

```js
var con1 = myConfig.connections.get('con1');
var con2 = myConfig.connections.get('con2');

console.log(myConfig.connections.get() === myConfig.connections.get('con1')); //will output true
```

<a name="configuration.get_section"></a>
### Configuration.getSection(name, type)
Get the specified section

yaml:

```yml
map
    default: mapbox
    providers:
        -
            name: mapbox
            type: MapBoxProvider
            connection: mapbox
        -
            name: gmap
            type: GoogleMapProvider
            connection: gmap
```

section:

```js
var MapSection = function(section) {
    /* ... */
};


```

usage:

```js
var map = myConfig.getSection('map', MapSection);
```

__Note:__

If no type passed to the method, get the raw section.

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