Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

configurations

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configurations

manages multiple, competing configurations

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-8.7%
Maintainers
1
Weekly downloads
 
Created
Source

configurations Build Status

NPM

NPM

Loads configuration files depending on the environment, the users individual configuration, additional configuration files that are explicitly defined and CLI parameters.

Interface

configuration#load(baseDir, additionalParameters)

Creates a configurations hash out of several overlapping configuration files.

  • baseDir the directory configurations are loaded from
  • additionalParameters optional additional Parameters e.g. from cli arguments

Logic

Default Configuration

The config file default.(js|json) is always loaded and is the base configuration.

Environment Configuration

The environment is used to load an additional configurations file. Naming convention is {environment}.(js|json). The environment configuration is optional.

User Configuration

For local development an configuration individual for every developer is useful. Will be only loaded if the environment is development. Naming convention is user.{userName}.(js|json). The user configuration is optional.

Additional parameters

Additonal parameters can be specified via a options hash that will be merged into the configuration. cli arguments are a possible source.

External optional additional Configuration

Via the parameters hash the path to an additonal configurations file can be specified. The key for the options hash os externalconfig.

Example

default.js

module.exports = {
    foo: 'bar',
    bax: 'baz',
    spam: 'eggs'
};

/foo/bar/optionalConfig.js

module.exports = {
    spam: 'eggs222'
};

Call

var path = require('path');
var c = require('configurations');

var configuration = c.load(path.join(__dirname, '/config'), {
  bax: 'bazzzz',
  externalconfig: '/foo/bar/optionalConfig.js'
});

Result

{
    foo: 'bar',
    bax: 'bazzzz',
    spam: 'eggs222'
}

Example 2

The file example/example.js contains the following content:

var configuration = configurations.load(path.join(__dirname, '/config'), {
    externalconfig: path.join(__dirname, 'config', 'optional.js'),
    foo: 'foo-cli'
});

Run it with the following parameters:

#1

$ NODE_ENV=development node example/example.js

result:

{ "a": "b", "foo": "foo-cli", "bax": "baz-development", "spam": "eggs2" }

#2

$ NODE_ENV=production node example/example.js

result:

{ "a": "b", "foo": "foo-cli", "bax": "baz-production", "spam": "eggs2" }

#3

$ NODE_ENV=foo node example/example.js

result:

{ "a": "b", "foo": "foo-cli", "bax": "baz", "spam": "eggs2" }

Keywords

FAQs

Package last updated on 01 Nov 2016

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