npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

config-discovery

v0.1.0

Published

A simple JSON configuration loading and compositing utility.

Downloads

17

Readme

What is it?

A simple JSON configuration loading utility.

What does it allow you to do ?

  • Look for a configuration file from a list of possible locations, and load the first one.
  • Create a composite configuration using patches from another config file or from the environment.

What makes it different from other config libraries?

  • It allows you to compose your configuration from different sources in one block of code.
  • It does not need any setups with any predefined directories. You're free.
  • Though environment JSON prototyping exists on other libraries, config-discovery gives you the freedom on how to organize your prototypes.

Why did you make this ?

This utility was built with containerizing backend NodeJS applications in mind. Configuration setups in containers almost always involve the use of K8s ConfigMaps and Secrets, which are mounted either as a file and/or as environment variables, config-discovery takes care of locating and compositing these configurations into a single json object for you.

Whats new in 0.1.0?

  • Stream lined interface for both patching, and find first method names.
  • Added support for Environment and JSON objects in for* and or* method families.
  • Added support for JSON objects in patching methods.
  • Removed tests from npm package, make it smaller.

Sample usage

Scenario 1: Just want to load a debug config.

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

...

let debugValues = {user: 'DebugDB', password: 'password'};

let configuration = new Config()
    .fromFile('/other/env/directory/config.json')
    .orObject(debugValues)
    .get();

////// OR

let prototype = {user: 'DB_USERNAME', password: 'DB_PASSWORD'}
let configuration = new Config()
    .fromFile('/other/env/directory/config.json')
    .orEnv(prototype)
    .get();

////// OR

let debugConfig = '/local/conf/myconfig.json'

let configuration = new Config()
    .fromFile('/other/env/directory/config.json')
    .orFile(debugConfig)
    .get();

const knex = Knex(configuration)

Scenario 2: Simply load a config outside the application.

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

...

let configuration = new Config()
    .fromFile('/configs/config.json')
    .get();

const knex = Knex(configuration)

Scenario 3: Prioritize a configuration based on location.

This will load the first configuration it finds, starting from fromFile().

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

...

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

const knex = Knex(configuration)

Scenario 4: Compositing a configuration.

This happens when sensitive data are provided with K8S Secrets, which can be mounted as a set of environment variables. Wrangle them into a JSON with a prototype!

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

...

let envPrototype = {connection: {user: 'SECRET_DB_USERNAME', password: 'SECRET_DB_PASSWORD'}};

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

const knex = Knex(configuration)

Or simply patch with another file.

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

...


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

const knex = Knex(configuration)