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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sharedconfig

v0.1.7

Published

Shared Configuration Interface using CouchDB as a backend

Readme

sharedconfig

The sharedconfig package is used to provide applications a mechanism for sharing application configuration information across a network of machines.

Why?

So why would you want to use sharedconfig over many of the other excellent node configuration libraries. Primarily, because this configuration engine is designed to grab configuration information from a single configuration server. Additionally, the CouchDB _changes feed is used (via nano and follow) to monitor changes in the config.

Combine this with the magic of xdiff and you have a really powerful little configuration service for your application. Here, let me show you:

Getting Started

To get started with sharedconfig you simply need to create a new sharedconfig instance:

var config = sharedconfig('http://damonoehlman.iriscouch.com/sharedconfig-test');

Once you have a config instance, you can then use a particular environment configuration. The use command operates asynchronously and fires a callback once the complete merged config has been loaded for the target environment.

config.use('dev', function(err, data) {
    console.log(data.a);
});

Merged config? What does that mean? Well, the merged config is the result of merging the data contained within the default document and the data contained within the requested environment. To get a feel for how this works in practice, why not have a look at the contents of the two documents that are merged within the test db:

default (http://damonoehlman.iriscouch.com/sharedconfig-test/default):

{
    "a": 5,
    "b": 5,
    "redis": {
        "host": "localhost",
        "port": 6379
    }
}

dev (http://damonoehlman.iriscouch.com/sharedconfig-test/dev):

{
    "a": 10
}

Which produces the merged results (via the lodash merge function) of:

{
    "a": 10,
    "b": 5,
    "redis": {
        "host": "localhost",
        "port": 6379
    }
}

After the use operation has completed, the configuration data will be made available directly on the created shared config object. In our case, this is a variable called config:

console.log(config.redis.host);
// => localhost

Now while all of this is useful in it's own right, it pales in comparison with what you can do when you combine the magic of the CouchDB _changes feed into the mix.

Once you are using a config environment / area that area will be monitored for changes, and this will generate events on the config object. Additionally, there are two types of config change events that are fired:

  • targeted updates using the update.setting.name event, e.g. update.riak.host; and
  • a blanket changed event that is triggered after the individual update events have been fired. It's important to note that at the moment the changed event will fire after a configuration is loaded regardless of whether anything changed in the config or not. I'm open to discussion about this.

Example Change Notifications

Handling config loads on environment selection / change:

config.use('dev').on('changed', function(settings) {
    // handle updates
});

Listening for targeted changes on a specific configuration property. These events are triggered when a configuration change is detected for a specific property. This can happen when either a different environment is selected using the use method, OR; a configuration update has been made to the CouchDB backend and it is picked up in the _changes feed:

config.on('update.redis.host', function(newHost) {
    console.log('The host has changed to: ' + newHost);
});

Additionally, because EventEmitter2 has been used for the events system, you can also listen for wildcard events:

config.on('update.redis.*', function() {
    // no point looking at the value
    // and might be worth throttling the handler to deal with the event being fired twice
    // if both the port and the host changed
    console.log('Redis config has changed: ', config.redis);
});