igthorn-config
v1.0.1
Published
Basic wrapper for loading configuration
Downloads
1
Maintainers
Readme
Igthorn Config
Basic wrapper for loading configuration.
Igthorn Config package provides smart config file loading mechanism allowing to use local/remote config overwrites(using nconf package) without worry to commit them. This package is part of Igthorn project.
Usage
Typical usage would be to instantiate config(optionally passing filename and/or directory):
let Config = require("igthorn-config");
let config = new Config();
// this will load:
// appRootPath + "/config/app.json"
// and extend it with
// appRootPath + "/config/app.env.json"
// or
let Config = require("igthorn-config");
let config = new Config("test");
// this will load:
// appRootPath + "/config/test.json"
// and extend it with
// appRootPath + "/config/test.env.json"
// or
let appRootPath = require("app-root-path");
let Config = require("igthorn-config");
let config = new Config("main", appRootPath + "/settings");
// this will load:
// appRootPath + "/settings/main.json"
// and extend it with
// appRootPath + "/settings/main.env.json"
later config
variable can be used in following way:
console.log(config.get("db:username"));
Methods
Config class implements following methods:
constructor(configFilename:string, configDirectoryPath:string) : self
allows to pass custom config filename and/or config directory. Otherwise they are defaulting to:
configFilename = "app" or NODE_ENV environment variable
configDirectoryPath = appRootPath + "/config"
get(key:string): mixed
returns key of configuration matched via passed key name