Socket
Socket
Sign inDemoInstall

bailiff

Package Overview
Dependencies
23
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bailiff

A config manager


Version published
Weekly downloads
7
decreased by-63.16%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Bailiff - A configs manager

Bailiff is a single point of config management.

Bailiff lets you access all your configs. Be it .env, json files, and it also supports a central config in mongo collection.

A central config can make it easy to share and manage common configs between your services, e.g. core DB configs.

Setup

Install

npm install --save bailiff

Add variable in ‘.env’ file in root of your service

You need this if you want to have central configs in Mongo DB.

BAILIFF_MONGO_USER="your-mongo-user"
BAILIFF_MONGO_PASS="your-mongo-pass"
BAILIFF_MONGO_HOST="your-mongo-host"
BAILIFF_MONGO_PORT="your-mongo-port"
BAILIFF_MONGO_DB="your-db-name"
BAILIFF_MONGO_COLLECTION="your-collection-name"

OR

BAILIFF_MONGO_URI="mongodb://user:pass@host:27017"
BAILIFF_MONGO_DB="your-db-name"
BAILIFF_MONGO_COLLECTION="your-collection-name"

How to use

Get a config from .env or central config from mongo

Add bailiff in your code.

const bailiffPromise = require("bailiff").default;

bailiffPromise.then(bailiff =>{
  bailiff.get("MY_CONFIG_VAR"); 
}) 
To add custom configurations
const bailiffPromise = require("bailiff").default;

OR

import bailiffPromise from "bailiff"
// To add custom Hash config data or/and a JSON file. You can chain addStore.
bailiffPromise.then(bailiff =>{
  bailiff.addStore({"MY_CONFIG_VAR": "MY_CONFIG_VALUE", "ANOTHER_CONFIG": "ANOTHER_VALUE"})
         .addStore("relative/path/to/your/json");
})

bailiff uses Singleton pattern. Add config store once and then use it later anywhere in the code in any file.

const bailiffPromise = require("bailiff").default;
const bailiff = await bailiffPromise();

bailiff.get("ANOTHER_CONFIG");
To access central configs from Mongo DB

Data structure of the mongo document should look like -

{
  "name": "MY_CONFIG_VAR",
  "value": "MY_CONFIG_VALUE",
  "status": 1
}

Make a unique index on name and status for fast search and accurate data.

You can access central config similar to other configs.

bailiff.get("MY_CONFIG_VAR");

Bailiff keeps a copy of central mongo config.

It does not read from MongoDB every time.

It only reads from MongoDB once on the service startup. That makes it very fast.

Priority of configs

Priority of configs are

  1. Custom added store
  2. Dotenv file
  3. Central config

This makes it easy to override central config if required.

Keywords

FAQs

Last updated on 03 May 2021

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