@creativefeather/config

darn small configuration framework for node apps

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@creativefeather/config
0.5.04 years ago5 years agoMinified + gzip package size for @creativefeather/config in KB

Readme

Config
My little project: a config module which aims to focus on making the important parts of environment, and app, configuration secure, simple, and easy to use. STATUS Basic basic features A-OK!

Quick Start

Install

$ npm install @creativefeather/config --save
After installing create the env.json config file in the {projectroot}/config directory. Add properties and enjoy! ```js // env.json || env.js { "development": {} } ```

Options

path

By default the module will look in the project root directory for a folder called config. The config path used to search for configuration files can be changed in various ways like so: ```js // package.json { "name": "my-module", "config": {
"config path": "path/to/config/dir"
} } // In Code (via module) const config = require('@creativefeather/config'); config({ use: true, // option to set module aquired config path: "path/to/config/dir" }); // In Code (before requiring the module) process.env.CONFIGOPTIONPATH = 'path/to/config/dir'; // Env Variable $ CONFIGOPTIONPATH=path/to/config/dir ```

env

If no environment is specified, the default will be "development"--however, if there is an environment specified in env.json that begins with 'prod', an error will be thrown instead. If you want to use a different configuration, some ways of specifying it are more practial than others for a typical project. . . ```js // Environment Variable $ NODEENV=production // OR $ CONFIGOPTIONENV=production // In Code (via module) const config = require('@creativefeather/config'); config({ use: true, // option to set module aquired config env: "production" }); // In Code (before requiring the module) process.env.NODEENV = 'production'; // OR process.env.CONFIGOPTIONENV = 'production'; // Env Variable $ CONFIGOPTIONENV=production ```

Config Files

index.json is where to put default values and values that aren't specific to a particular deployment or sensitive in anyway. It is not required to have this file; but, you should be aware of it for when the need arises. env.json is where sensitive info and environment specific settings will go. That way, you don't have to commit any of it to the public. ```js // Example Usage // env.js { "all": {
"db": {
"username": "cmonster",
"password": "chocolatechip",
"host": "localhost",
"port": 3000
}
}, "development": {
"logger": new Logger({
"level": "info"
}),
"db": {
"name": "coolapp"
"name+TEST": "test"    
}
} } // index.json { "logger": null } ``` If you have more than one configuration in env.json
, you can put shared values in "all". Properties in the active configuration will override the values in 'all'. Finally, 'env' will be merged with 'index' where 'env' values take priority.