npm package: @kobionic/node-config-client
Description: Library to interact with the Node Config Server project and easily request configuration from it.
Author: Jeremie Rodriguez
Latest version: 1.0.2

# Node Config Client

[![npm version](https://img.shields.io/npm/v/@kobionic/node-config-client.svg?style=flat)](https://www.npmjs.com/package/@kobionic/node-config-client)
[![Build Status](https://img.shields.io/travis/KoBionic/node-config-client-js.svg)](https://travis-ci.org/KoBionic/node-config-client-js/branches)
[![Dependencies Status](https://img.shields.io/david/kobionic/node-config-client-js.svg)](https://david-dm.org/kobionic/node-config-client-js)
[![DevDependencies Status](https://img.shields.io/david/dev/kobionic/node-config-client-js.svg)](https://david-dm.org/kobionic/node-config-client-js?type=dev)
[![License](https://img.shields.io/npm/l/@kobionic/node-config-client.svg)](https://github.com/kobionic/node-config-client-js/blob/master/LICENSE)

Library to interact with the Node Config Server project and easily request configuration from it.

## Installation

The Node Config Server project is deployed on **npm**.
It can be installed as easily as typing below command:

```bash
npm install --save @kobionic/node-config-client
```

## Configuration

Configuration of the client can be done by either using **environment variables** or directly passing a configuration object when instantiating the service.

### Configure by setting OS environment variables

| Variable        | Type   | Default           | Description                                        |
| --------------- | ------ | ----------------- | ---------------------------------------------------|
| `API_VERSION`   | number | 1                 | the *API version* to use                           |
| `PORT`          | number | 20490             | the Node Config Server *port number*               |
| `HOST`          | string | computer hostname | the Node Config Server *hostname*                  |
| `HTTP_PROTOCOL` | string | http              | the HTTP protocol to use, either *http* or *https* |

### Configure by passing a configuration object

#### Object type

```typescript
type Configuration = {
    /** The Node Config Server API version to use. */
    apiVersion?: string | number;
    /** The Node Config Server hostname. */
    host?: string;
    /** The Node Config Server HTTP protocol to use. */
    httpProtocol?: 'http' | 'https';
    /** The Node Config Server port number. */
    port?: string | number;
};
```

#### Example

```javascript
const configuration = {
    apiVersion: 1,
    host: os.hostname(),
    httpProtocol: 'http',
    port: 20490
};

const client = new NodeConfigClient(configuration);
```

## How To Use

Most methods available in the client are chainable and makes its utilization trivial.

```javascript
const client = new NodeConfigClient();

client
    .folder('those')
    .folder('are')
    .folders('fake', 'folders')
    .file('configuration.json')
    .property('rootProperty')
    .properties('nestedProp1', 'nestedProp2')
    .get() // request URL would be http://localhost:20490/api/v1/those/are/fake/folders/configuration.json/rootProperty/nestedProp1/nestedProp2
    .then(data => console.log) // data is displayed in console
    .catch(err => console.error); // if an error occured during request
```

## Authors

* [**Jeremie Rodriguez**](https://github.com/jeremiergz) &lt;[contact@jeremierodriguez.com](mailto:contact@jeremierodriguez.com)&gt; - Main developer

## License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.