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

painless-config

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

painless-config

Low friction library for application configuration.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
78
increased by62.5%
Maintainers
3
Weekly downloads
 
Created
Source

Version License Downloads

painless-config

Low friction library for application configuration.

Why another configuration library?

There were 14 configuration libraries so we needed to build one to unify them all, there are now 15 configuration libraries.

XKCD Comic From: https://xkcd.com/927/

In all seriousness, we were looking for a configuration library that had the following traits:

  1. Has a low barrier to entry and is simple
  2. Primarily uses environment variables (usually for production)
  3. Could fallback to a file (usually for local development)
  4. High performance (especially when using environment variables)

Usage

Add a dependency to the npm package:

npm install painless-config --save

Require the module and then retrieve the configuration settings you want:

var config = require('painless-config');
var widgetPath = config.get('WIDGET_PATH');

You can also retrieve all settings as a complex object:

var allSettings = config.all();

Any - or _ in the environment variable's name will be used to create the object's structure. For example, given these environment variables:

RECT_WIDTH=16
RECT_HEIGHT=9

This object would be returned:

{
  "RECT": {
    "WIDTH": 16,
    "HEIGHT": 9
  }
}

Resolution order

Configuration settings will be resolved in this order:

  1. Environment variable
  2. Closest ancestor env.json to the working directory
  3. Return undefined

Fallback

If an environment variable cannot be found then the library will begin walking up the tree from the current working directory until it finds an env.json file.

The env.json must have the following structure:

{
  "setting1": "value1",
  "setting2": "value2"
}

Contributing

Pull requests that honor the traits above will gladly be considered!

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Keywords

FAQs

Package last updated on 22 Oct 2020

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