npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bailiff

v3.1.3

Published

A config manager

Downloads

74

Readme

Bailiff - A configs manager

The 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 the 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 variables in the ‘.env’ file in the root dir 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

Initialize central config of mongo

You can skip this part if you are not using central config.

Run bailiff-init before starting your node application.

We recommend you add this in the scripts section of your package.json.

eg: prestart: "bailiff-init" or prestart: "npx bailiff-init"

Get a config from .env or central config from mongo

Add bailiff in your code.

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

bailiff.get("MY_CONFIG_VAR"); 

To add custom configurations

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

OR

import bailiff from "bailiff"
// To add custom Hash config data or/and a JSON file. You can chain addStore.

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 bailiff = require("bailiff").default;

bailiff.get("ANOTHER_CONFIG");

To access central configs from Mongo DB

The data structure of the mongo document should look like this -

{
  "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 the 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.