Socket
Socket
Sign inDemoInstall

confide

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

confide

simple app configuration


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

confide

Confide is a simple configuration module for node.js. It will merge an environment-specific configuration file with a default configuration file and return the merged values.

Assume the directory structure:

|- config
|  |- default.json
|  |- production.json
|- node_modules
|  |- confide
|- myscript.js

Any property declared in a default config file may be overridden by an environment-specific config file.

// in default.json
{
  "showLogMsgs": true // will be overridden below
  "dateFormat": "MM/DD/YYYY" // will not be overridden below
}

// in production.json
{
  "showLogMsgs": false
  // inherit dateFormat
}

In myscript.js, we can read our configuration by invoking confide's load() method:

var path = require('path'),
  CONFIG_DIR = path.join(__dirname, 'config'),
  confide = require('confide');

confide({configDir: CONFIG_DIR}).load('production', function (err, mergedConfig) {
  mergedConfig.showLogMsgs; // false
});

The confide function takes a number of parameters:

  • configDir (required) - directory where configuration files are located
  • defaultEnv (optional, defaults to default) - name of the default env (default json file)
  • cache (optional, defaults to true) - whether to cache config values for future calls to load()

If you don't need environment-specific configuration, you can just create default.json in your config directory, and leave out the environment parameter when calling load():

confide({configDir: CONFIG_DIR}).load(function (err, defaultConfig) {
  defaultConfig.showLogMsgs; // true
});

If cache is enabled (it is by default) and you wish to focibly reload your configuration, just call the reload() method with the same parameters as load():

var conf = confide({configDir: CONFIG_DIR});
conf.load('production', function (err, mergedConfig) {
  mergedConfig.showLogMsgs; // false

  // production.json updated on the file system...
  conf.reload('production', function (err, mergedConfig) {
    mergedConfig.showLogMsgs; // true
  });
});

Keywords

FAQs

Package last updated on 30 Jan 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc