Nietzsche's Preposterous Moustache
    Have ideas to improve npm?Join in the discussion! »

    ravel-etcd-config

    0.18.0 • Public • Published

    ravel-etcd-config

    Distributed Ravel configuration via etcd

    GitHub license npm version Dependency Status npm Build Status Code Climate Test Coverage

    Ravel has a managed configuration system which is traditionally supplied values via a .ravelrc file. While this is convenient for development, production deployments with replicated Ravel apps benefit from utilizing a distributed configuration approach. To that end, this module provides a mechanism for loading configuration parameters from etcd, a popular open-source key/value store which is often utilized for this purpose.

    This module can be used with any version of etcd which supports the v2 API (this includes etcd 3.x).

    Example Usage:

    Load parameters into a folder in etcd using the tool or language of your choice:

    # Notice that parameters live within the ravelrc directory by default, 
    # and that parameter names with spaces are supported. 
    $ etcdctl set "/ravelrc/redis host" 1.2.3.4
    $ etcdctl set "/ravelrc/redis port" 6379
    $ etcdctl set "/ravelrc/my object parameter" "{\"a\": 1, \"b\": 2}"

    Then consume the parameters in your Ravel application:

    app.js

    const app = new require('ravel')();
    const EtcdConfig = require('ravel-etcd-config');
    new EtcdConfig(app);
    // OPTIONAL: set connection host. It'll hit 127.0.0.1:2379 by default.
    app.set('config etcd host', 'http://1.2.3.4:2379');
    // OPTIONAL: set connection parameters. {timeout: 5000} by default.
    // see https://github.com/stianeikeland/node-etcd for options
    app.set('config etcd options', {timeout: 1000});
    // ... other providers and parameters
    app.modules('./modules');
    app.resources('./resources');
    // ... the rest of your Ravel app
    app.init();
    app.listen();

    Advanced Usage:

    If you wish to utilize a unique directory name for your configuration parameters, or even load parameters from multiple directories, you can supply a name manually:

    # Notice that parameters live within the ravelrc directory by default, 
    # and that parameter names with spaces are supported. 
    $ etcdctl set "/ravelrc/redis host" 1.2.3.4
    $ etcdctl set "/customer1/redis port" 6379
    $ etcdctl set "/customer1/my object parameter" "{\"a\": 1, \"b\": 2}"

    .ravelrc

    {
      "config etcd host": "http://1.2.3.4:2379",
      "config etcd options": {
        "timeout": 1000
      }
    }

    app.js

    const app = new require('ravel')();
    const EtcdConfig = require('ravel-etcd-config');
    // in this example, .ravelrc configures etcd and all other params are loaded from there
    new EtcdConfig(app); // this loads from /ravelrc by default
    new EtcdConfig(app, 'customer1'); // this will load from /customer1
    // ... other providers and parameters
    app.modules('./modules');
    app.resources('./resources');
    // ... the rest of your Ravel app
    app.init();
    app.listen();

    Keywords

    none

    Install

    npm i ravel-etcd-config

    DownloadsWeekly Downloads

    4

    Version

    0.18.0

    License

    MIT

    Last publish

    Collaborators

    • avatar