superconfig
Lightweight config loader.
Install
npm install superconfig --save
Introduction
In large applications you have to deal with a lot of configuration variables. There are plenty of configuration modules out there that expect you to only have one configuration file for each environment. However, when your application grows you may want to encapsulate your variables in separate files in order to keep things overseeable. For example one file for your databases, one file for your server setup and so on. You probably also have some variables that doesn't change throughout your environments. If you only have one file for each environment you need to define every variable for each environment - even if they do not differ.
superconfig let's you...
- define your configuration variables in separate files
- have separate directories for your environments
- have a default set of variables that can be overriden by variables of your actual environment
Usage
Your config directory may look like this:
/config
/production
database.js
server.js
/development
database.js
Set up superconfig in a separate file
// config.jsvar superconfig = ; moduleexports = ;
Use your configuration variables
var config = ; // Pass the whole database configurationvar database = ; // Use a single valuevar user = ; // If you are working in the development environment// superconfig will use the server configuration of your// production environment, since we didn't provide one// for the development environmentserver;
Nested directories/variables
You can work with nested directories:
/config
/production
/database
mysql.js
sqllite.js
Access your variables like:
var user = ;
API
superconfig(options)
Params
-
options
{Object}options.path
{String} Path to your config directoryoptions.env
{String} The actual environmentoptions.denv
{String} Your default environment
-
Returns
- {Function} Invoking superconfig() returns a getter function, that let's you access your variables
- The function takes a path to your variable e.g.
database.user