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)

In defense of the modern web

I expect I'll annoy everyone with this post: the anti-JavaScript crusaders, justly aghast at how much of the stuff we slather onto modern websites; the people arguing the web is a broken platform for interactive applications anyway and we should start over;

React users; the old guard with their artisanal JS and hand authored HTML; and Tom MacWright, someone I've admired from afar since I first became aware of his work on Mapbox many years ago. But I guess that's the price of having opinions.