@wandersonwhcr/config

1.1.1 • Public • Published

config

A Simple Configuration Loader for Node.js

Travis npm license

Usage

This package can be used to load configurations asynchronously using Promises.

// Dependencies
const Config = require("@wandersonwhcr/config").Config;

// config/default.d/00-default.json   -> { "foo": "bar" }
// config/default.d/10-something.json -> { "baz": "qux" }
// config/local.d/99-local.json       -> { "foo": "one", "somebody": "someone" }

// Construction
var config = new Config([
    "config/default.d/*.json",
    "config/local.d/*.json"
]);

// Fetch Files
config.fetch().then(function (config) {
    // { "foo": "one", "baz": "qux", "somebody": "someone" }
}).catch(function (error) {
    // Whoops!
});

Synchronous configuration loading can be used directly, but it's not recommended.

// Fetch Files (Sync)
var result = config.fetchSync();
// { "foo": "one", "baz": "qux", "somebody": "someone" }

Reason

I created this package because I didn't find any other package that loads files by glob and merges them alphabetically by filename. This package is very inspired by Zend Framework's configuration loading and a lot of Linux packages that load configuration from directories (aka conf.d directories).

License

This project is licensed under MIT License. See LICENSE file for details.

Package Sidebar

Install

npm i @wandersonwhcr/config

Weekly Downloads

2

Version

1.1.1

License

MIT

Last publish

Collaborators

  • wandersonwhcr