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

envcfg

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envcfg

stupid simple environment aware configuration

  • 0.0.2
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

envcfg

envcfg is an environment aware configuration module. It is inspired by settings and cfg.

It can load configurations from json files, modules or just plain objects. Do note that when loading from disk readFileSync or require will be used.

Install


npm install envcfg

Usage


The configuration can be broken down by environment, with the special * key which can be used to share common settings across all environments.

Files


Files can be loaded by passing the path to file that follows the structure above. If the file ends in .json it will be assumed it is a JSON file and will be parsed accordingly.

var envcfg = require('envcfg');
var config = envcfg(__dirname + '/path/to/config.json');
{
	"*": {
		"foo": "foo-*",
		"buz": "buzz-*"
	},
	"development": {
		"bar": "bar-development"
	},
	"test": {
		"foo": "foo-test",
		"bar": "bar-test"
	}
}

Modules


Loading modules by path is not different than loading JSON besides the naming convention. Just be sure the module sets it's module.exports to the configuration.

var envcfg = require('envcfg');
var config = envcfg(__dirname + '/path/to/config_module');
module.exports = exports = {
	"*": {
		"foo": "foo-*",
		"buz": "buzz-*"
	},
	"development": {
		"bar": "bar-development"
	},
	"test": {
		"foo": "foo-test",
		"bar": "bar-test"
	}
}

Programmatically


It is also possible to pass in a plain object.

var config = require('envcfg')({
	"*": {
		"foo": "foo-*",
		"buz": "buzz-*"
	},
	"development": {
		"bar": "bar-development"
	},
	"test": {
		"foo": "foo-test",
		"bar": "bar-test"
	}
});

Mutability


Ever have anyone muck around with your configuration settings? No worries, the object returned from envcfg cannot be tampered with. In strict mode exceptions will be thrown and in none-strict mode, they will be ignored.

'use strict';

var config = require('envcfg')({
	"*": {
		"foo": "foo-*",
		"buz": "buzz-*"
	},
	"development": {
		"bar": "bar-development"
	},
	"test": {
		"foo": "foo-test",
		"bar": "bar-test"
	}
});

// throws on re-setting
config.buzz = "buzz off"; // throws TypeError

// throws on setting new values
config.something_new = 'wtf'; // throws TypeError

FAQs

Package last updated on 04 May 2012

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