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

makeen-config

v0.5.0

Published

Makeen configuration strategy

Downloads

26

Readme

makeen-config provides a comprehensive way to manage configuration for your project.

A glimpse of how configuration works:

import Config, { stores } from 'makeen-config';

const { Memory } = stores; // keeps the data in memory
const config = new Config();
const store = new Memory({
  // some initial data for the store
  it: 'works',
});

config.addStore(store); // we add the store to the stack of stores

// config.get always returns a promise
config.get('it').then(value => {
  console.log(value); // "works"
});

The idea behind configuration is that you initialize a Config object and then you add different data stores to it.

The Config object will provide a read-only interface for the data that's in the stores - you can't write to the Config object - you have to do that through the stores you add to it. It will also maintain a stack of stores. When you ask it for some data, it will first try to get it from the last store added to the stack, then the one before it etc..

If it finds some data, it will be cached so that it's retrieved very fast on subsequent calls. It will be developer's responsibility to clear the cache if he made changes to the stores. You can also disable this caching by instantiating a Config object with a null cache.

For now there are only 2 types of data stores available: Memory (stores the data in memory) and Env (reads / writes to process.env). Later on more types of stores will be added: MongoDB, Redis, JSON, Http etc.

import Config, { stores, caches } from '../index';

const { Memory } = stores;
const { Null } = caches;
// the first argument of a Config object is a cache instance and we're going to use a Null cache to disable any caching from happening
const config = new Config(new Null());
const store = new Memory({
  it: 'works',
});

config.addStore(store);

config.get('it').then(value => {
  console.log(value); // "works"
});

A common scenario to manage your configuration for an app is the following:

  • you create a Config instance and use it as a singleton at the application level
  • the stores that will be added to the Config object are:
    • a Memory store that you'll use to setup some default configuration
    • an Env store for machine specific configuration (passwords, keys etc)
    • a db-aware store (Mongo, Redis) - for application configuration that can be managed by an admin user through some UI (list of blacklisted / whitelisted IPs etc)
  • you can use a Memory cache when instantiating the Config object, but don't forget to clear this cache whenever you're making changes changes to the stores.

You can clear the cache either by running Config.clearCache(key) or Config.clearCache(), where the last one with clear the entire cache.