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

epdoc-config

v2.0.7

Published

Config loader supporting mixin of multiple config files with subsections for default and environment-specific configuration

Downloads

4

Readme

epdoc-config

Config loader and validator.

The epdoc-config library provides a mechanism to load environment-specific config settings that are merged from a list of json config files that you specify. JSON config files are loaded in order, with the later files overwriting earlier settings. JSON config files may contain a configExt (config extension) to reference another config file to load. Config files added in this manner are loaded, in the order they are encountered, after all previous config files are loaded. This allows a config file to specify a chain of config files to be loaded.

Within each config file, the loader will first load config settings from the object named defaults, and will then load settings from the object specified by the first parameter of the init method (usually this is ENV development or production). The end result is a single config object that is merged from the various sources.

JSON Config File Syntax

Example config JSON file:

{
	"production": {
		"dbName": "test",
		"db:org": {
 			"driver": "mysql",
 			"host": "10.179.6.27"
 		}
	},
	"development": {
		"dbName": "dev.db"
	},
	"defaults": {
		"dbName": "test",
		"logFile": "${HOME}/log/${DATE}_${PID}_console.log"
	}
}

How to use this module in your application

Install the node package.

npm install epdoc-config

Initialize once on launch.

var Config = require('epdoc-config');
var moment = require('moment');
var env = 'development';
var files = ['path/to/project.settings.json'];
var opts = {
    replace: {
        home: "/User/bob",
        app: "/User/bob/dev/myproject",
        date: moment(logger.getStartTime()).format('YYYYMMDD_HHmmss'),
        pid: process.pid
    }
};

// Read the config files and replace instances of '${HOME}', etc with the values in opts.replace 
Config.init(env,files,opts);
// Now get the constructed config object
var config = Config.get();

Once initialized, access the config file from elsewhere in your code:

var config = require('epdoc-config').get();

API

init

Initialize and return config settings, reading from a list of config files, with the last file in the list overwriting previous files. If configExt is found to be set to a string or arrays of strings in any of the loaded config files, then the array of all extended config files will be loaded once the initial list of config files is loaded.

Parameters

  • env Environment NODE_ENV, usually one of development, production, staging, test.
  • configFileList List of config files to load
  • options An object with the following properties: ** replace An object with key, value pairs where ${KEY} is to be replaced with value in all config strings. key is made uppercase. ** flat Support loading flat files that do not have 'defaults' and 'env' subsections. If the file does not contain a section named 'defaults', a section named for the specified environment, or a top level entry"_type": "tree", then the file is loaded as a flat file. To ensure that files that are not flat get loaded properly, please always ensure that they contain a 'defaults' section or that the top level object contains the property "_type": "tree".

Returns

The Config object.

Example:

var Config = require('epdoc-config').init('staging',['path/to/project.settings.json']);

get

Return the resultant config settings. Must call init() before calling this method.

Returns

The resultant config settings, resolved by loading from the list of config files.

Example:

var config = Config.get();

extend

Copy all of the properties in the source objects over to the config object, and return the config object. It's in-order, so the source will override properties of the same name in previous config.

Returns

The resultant config settings.

Example:

var config = Config.extend({url:"http://my/path"});