1.0.2 • Published 7 years ago

@kobionic/node-config-client v1.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 years ago

Node Config Client

npm version Build Status Dependencies Status DevDependencies Status 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:

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

VariableTypeDefaultDescription
API_VERSIONnumber1the API version to use
PORTnumber20490the Node Config Server port number
HOSTstringcomputer hostnamethe Node Config Server hostname
HTTP_PROTOCOLstringhttpthe HTTP protocol to use, either http or https

Configure by passing a configuration object

Object type

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

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.

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

License

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