Low friction library for application configuration.
Перейти к файлу
Jeff Wilcox 2591674ddf
Merge pull request #8 from microsoft/users/GitHubPolicyService/df6b3c4a-4587-4e5d-9d92-f33feae6a95a
Adding Microsoft SECURITY.MD
2022-09-01 11:10:24 -07:00
lib Add TypeScript declaration 2018-07-20 10:42:56 -07:00
.gitattributes Added Git configuration 2016-02-12 09:27:07 -08:00
.gitignore Added Git configuration 2016-02-12 09:27:07 -08:00
LICENSE Update LICENSE 2020-09-25 13:37:39 -07:00
README.md Update markdown core to the correct syntax formatter 2018-10-09 21:52:24 +03:00
SECURITY.md Microsoft mandatory file 2022-09-01 18:07:13 +00:00
index.js Add license header 2016-03-10 17:00:48 -08:00
package-lock.json Dependency update: object-path 2020-10-22 01:33:07 +00:00
package.json Dependency update: object-path 2020-10-22 01:33:07 +00:00

README.md

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.