Environment aware config reader that follows our conventions at &yet.
#getconfig - config fetcher for node.js
Managing configs for different environments is kind of a pain.
In short I wanted it to:
NODE_ENVenvironment variable to grab appropriate config
var config = require('getconfig')from anywhere in the app and have it Just Work™
npm install getconfig
config/default.jsonfile in the same folder as the main entry point (usually project root)
var config = require'getconfig';
Getconfig looks for a config directory in the same folder as the main entry point of your app. Your configuration files should be contained within that directory.
The configuration files attempted by require, in order, are:
Note that we don't list extensions, that's because the files are loaded via node's
require mechanism, so anything node can require will work.
In the event that
NODE_ENV is not set, getconfig will attempt to load
development in its place.
In certain circumstances, when your app isn't run directly (e.g. test runners) getconfig may not be able to lookup your config file properly. In this case, you can set a
GETCONFIG_ROOT environment variable to the directory where your config directory is located.
getconfig will always fill in the
getconfig.env value in your resulting config object with the current environment name so you can programatically determine the environment if you'd like. If no
NODE_ENV is set it will also set
0.x.xrange per semver conventions.
devenviroments now look for related config files. So if you've set your
developmentand it will still find a file called
0.3.0- Switching from JSON.parse to ALCE to allow single quotes and comments. Better readme.