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

config-ninja

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-ninja

Environmental JSON config.

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Config-Ninja

A quick and easy way to read in config files from disk depending on the enviroment. By default Config Ninja uses the NODE_ENV environment variable to determin whether we are running in production mode, otherwise development mode is assumed.

Important: The production config is always the default config. If you specify another enviroment, Config Ninja will copy the properties from that environment into the production config, overwriting any values that already exist. Nested properties will be respected. No changes are saved to disk.

Quick Start

// On application load prepare the ninja.
var config = require('config-ninja').init('/path/to/cfg/dir/');

// In another module we need config again...
var config = require('config-ninja');

// Use our config.
console.dir(config);
console.log('Super:', config.nested.super);

Override Environment

By default production and development environment strings are understood. If you have additional environments you can override the environment string by passing in a second parameter env:

var config = require('config-ninja').init('/path/to/cfg/dir/', 'staging');

Where env is the name of your config file e.g. staging.config.json.

Setup Config Files

Typically you will need 2 config files, one for production and one for development. You may also want config files for other enviroments such as staging.

/myConfig
  /production.config.json
  /staging.config.json
  /development.config.json
  /custom.config.json

FAQ

How can I tell the enviroment my config was initialised with?

The enviroment string for a given config variable is stored under config._env. Warning: If any of your config files contain a property called _env this will overwrite config._env.

How can I reload my config?

Simply call config.init() again without any parameters. Warning: If any of your config files contain a property called _cfgPath this will break and you will need to specify the directory path again.

How can I change the enviroment of my config during runtime?

Call config.init(null, 'new-environment-string'); This will reload the config with the new environment.

Can I load config from a database?

No. That's beyond the scope of this module.

Keywords

FAQs

Package last updated on 16 Mar 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