lib-config-etcd
config lib with etcd support
Last updated 5 years ago by hereandnow .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install lib-config-etcd 
SYNC missed versions from official npm registry.

lib-config-etcd

config lib with etcd support

Installation

$ npm install config-etcd --save

Benutzung

NODE_ENV

Set this environment var in your home-directory (eg. ~/.bash_profile) or run this application with --NODE_ENV=...

Necessary files

  • config/config.json
  • config/{env}.json (where ENV is the environment var NODE_ENV)

ENV

config-etcd can load values form envioronment variable. Use the prefix ENV:: to load a config value from an environment variable:

$ export MYKEY=0123456789

Used in config.json:

{
    "config": {
       "key": "ENV::MYKEY"
    }
}

ETCD

Using ETCD

ETCD is a highly-available key value store for shared configuration and service discovery. You can define configuration options that will result in an etcd lookup by using an ETCD_HOST:: and ETCD_PORT:: prefix like this in your config file:

{
    "config": {
       "serviceLocationHost": "ETCD_HOST::myService"
       "serviceLocationPort": "ETCD_PORT::myService"
    }
}

To alow config-etcd to find service in ETCD, the service has to be registerd e.g. by using discover config-etcd uses internal the discover-client

Configuring ETCD

config-etcd uses envioronment variable or CLI-parameter ETCD_HOST, ETCD_PORT, ETCD_PREFIX to find the ETCD Servers.

Default values are the following

  • ETCD_HOST localhost
  • ETCD_PORT 4001
  • ETCD_PREFIX discover

Example.coffee

configEtcd = require 'config-etcd'

configEtcd.on 'loaded', ->
  config = configEtcd.getConfig()
  # start application

configEtcd.on 'changed', ->
  newConfig = configEtcd.getConfig()
  # reconfigure application

configEtcd.load()

see folder examples

Api-Dokumentation

[doc/index.html]

Methoden

load(configPath, callback)

configPath

Type: String Default value: ./config

callback

Type: Function Default value: null

load() load's the config. Config loading is async since it has to make network calls to etcd.

getConfig()

getConfig() get the current config values. Only avalible after the loaded event got fired.

on(event, cb)

event

Type: String Default value: null

callback

Type: Function Default value: null

on('event', cb) register event handler

Events

loaded

event fires when config is load and getConfig() can be used.

changed

event fires when a config change in etcd happes. To get the updated config value use getConfig()

Development

use git-flow!

clone repo
$ git clone git@github.com:valiton/node-lib-config-etcd.git
install dependencies
$ npm install
Development-Workflow/ and watch (each code change restarts the build)
$ grunt dev
lint, test and build api-docs

runs internal grunt

$ npm test
create release
$ grunt release:xxx ( xxx = major || minor || patch )

Release History

0.1.0 - Initial Version

Authors (Valiton GmbH)

  • Johannes Stark
  • Benedikt Weiner
  • Bastian Behrens

License

Copyright (c) 2015 Valiton GmbH Licensed under the MIT license.

Current Tags

  • 0.4.1                                ...           latest (5 years ago)

3 Versions

  • 0.4.1                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (6)
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |