New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json4config

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

json4config

A simple and minimalist environment-aware configuration provider

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

json4config

A simple and minimalist environment-aware configuration provider

Installation

Run npm i json4config and start using it :-)

Introduction

Use the following code to conveniently get config values for a environment (in this case prod - see end of first line):

const cfg = require('json4config')('./config.json', 'prod');

console.log(cfg.get('mailing.host'));
console.log(cfg.get('mailing.port', 25)); // <-- Default fallback value
console.log(cfg.config); // <-- Raw config object

from a central config.json file with the following contents:

{
  "dev": {
    "mailing": {
      "host": "localhost"
    },
    "port": 10001
  },
  "prod": {
    "extends": "dev",
    "mailing": {
        "host": "smtp.gmail.com"
    },
    "port": 80
  },
  "app.mydomain.tld": {
    "extends": "prod",
    "mailing": {
        "host": "custom-smtp.myserver.foo",
        "port": 465,
        "useSSL": true
    }
  }
}

Features

  • Put different config values in a single config.json for a NodeJS application
  • Use the keyword extends inside an environment configuration to get all config keys from the provided environment. This way overwriting just only some values is very easy
  • It is easy to place config values for different target systems of the same application in one place
  • Provide either as a second parameter the name of the environment or add the commandline switchs -e prod or --env prod or place it inside the NODE_ENV system environment variable
  • Access can be gained either by using the function get(key, defaultValue) with a default value or by using the config key which contains the entire object
  • See the example in examples/
  • Uses tests to ensure working code

ToDo's

  • Tests need to be extended, to also test the commandline switches and NODE_ENV system variable

  • This documentation needs to be extended with the optional parameters and the normalization feature of environment names

Keywords

FAQs

Package last updated on 03 Oct 2018

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