DEV Community

SiegfredRodriguez
SiegfredRodriguez

Posted on

A simple yet handy configuration compositor and locator!

I finally dipped my toes in opensource, with my simple unopinionated yet capable configuration utility config-discovery!

  • Will not force you on any conventions such as directory and specific files.
  • Uses fluent interface, no strange incantations.
  • Fit for containerized deployments where configurations maybe split between ConfigMaps and Secrets.

Github
NPMJS

Some of its features include the ability to define a source priority for your configuration, including environment and directly from an object!

let Config = require('config-discovery');

....

let configuration = new Config()
    .fromFile('/configs/config.json')
    .orFile('/configuration/config.json')
    .orFile('/etc/my_configs/config.json')
    .orEnv(prototype)
    .orObj(configObject)
    .get();

Enter fullscreen mode Exit fullscreen mode

Compose a configuration from multiple sources, including the environment!

let prototype = {user: 'DB_USERNAME', password: 'DB_PASSWORD'}

let configuration = new Config()
    .fromFile('/configs/config.json')
    .orFile('/configuration/config.json')
    .orFile('/etc/my_configs/config.json')
    .thenPatchWith()
    .env(prototype)
    .get();

// or from another file

let configuration = new Config()
    .fromFile('/configs/config.json')
    .orFile('/configuration/config.json')
    .orFile('/etc/my_configs/config.json')
    .thenPatchWith()
    .configFile(/etc/secrets/credentials.json)
    .get();

// or from another object

let configuration = new Config()
    .fromFile('/configs/config.json')
    .orFile('/configuration/config.json')
    .orFile('/etc/my_configs/config.json')
    .thenPatchWith()
    .object(secretsJson)
    .get();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)