@kobionic/node-config-client
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

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

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.

Package Sidebar

Install

npm i @kobionic/node-config-client

Weekly Downloads

4

Version

1.0.2

License

Apache-2.0

Unpacked Size

42.1 kB

Total Files

6

Last publish

Collaborators

  • jeremiergz