Socket
Socket
Sign inDemoInstall

cfgapp

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cfgapp

Application config management library


Version published
Weekly downloads
7
Maintainers
1
Install size
260 kB
Created
Weekly downloads
 

Readme

Source

NodeJS config repository

Dotenv wrapper

Set up config

Configuration singleton is created in the main file. If defaultsPath property is provided defaults are red at the moment of config creation. Defaults must be a JSON file.

import {createAppConfig} from 'cfgapp';

createAppConfig([{type: 'json', source: './constants.json'}]);

Use config

Config can be accessed anywhere in application right after createAppConfig() call.

Options from .env file overrides defaults (if any are loaded). For example if option exists in both .env and defaults file, value from .env will be returned by get() call.

In cases when option itself must persist in .env for documentation purposes but contain default value, option's value can be set to "~" (tilde).

import appCfg from 'cfgapp';

const result = appCfg('MY_OPTION');
console.log(result);

Advanced usage

Sometimes it is not enough to have option value only as string. For example you might need to load structured config into some factory object. In those cases you can create option with object structure in defaults file. And override only environment specific parts.

defaults.json

{
    "COMPLEX_OPT": {
        "user": "johndoe",
        "pass": "%PASS%"
    }
}

.env

PASS=TheVerySecretPass
import {createAppConfig, appCfgObject} from 'cfgapp';

createAppConfig([{type: 'json', source: './constants.json'}]);

const result = appCfgObject('COMPLEX_OPT');
console.log(result['pass']); // outputs: TheVerySecretPass

Keywords

FAQs

Last updated on 26 Dec 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc