file-config-reader
v0.1.1
Published
A simple module for loading/merging local and global JSON configuration files.
Downloads
5
Readme
file-config-reader
A simple module for reading and merging config files that are stored "locally" (current working tree) and "globally" (home directory).
This module was built primarily for use when writing command-line (CLI) programs in Node.js. It implements some features from a few of my favorite command-line applications:
- JSHint - looks for config files not just in the working directory, but also in parent directory.
- Git - looks for config files in both a "local" and "global" location.
Instead of passing options to the command-line, it's often beneficial to store program-specific options in a configuration file. Additionally, you may want to maintain project-specific configuration files and/or a global configuration file for shared cross-project settings (i.e. 'git'). Also, when working within subdirectories of a project folder, it's often useful for a command-line utility to search upwards in the directory tree for a configuration file, so you don't constantly need to navigate back to the location of the configuration file (i.e. JSHint).
Note: Currently, this module only supports files with JSON content.
Install
npm install file-config-reader --save
Usage
> pwd
/Users/andre/dev/projects/cli_reader
> cat conf.json
{
"projectName": "cli_reader_sample",
"email": "[email protected]"
}
> cat $HOME/conf.json
{
"firstName": "Andre",
"lastName": "Giannico",
"email": "[email protected]",
age: 31
}
var FileConfigReader = require('file-config-reader');
var conf = new FileConfigReader('conf.json');
console.log(conf.firstName);
// output
"Andre"
console.log(conf);
// output
{
projectName: "cli_reader_sample",
firstName: "Andre",
lastName: "Giannico",
email: "[email protected]",
age: 31
}
License
Copyright 2014 Andre Giannico MIT License (enclosed)