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

feature-client

v1.0.3

Published

Node.js client for consumption of XPRMNTL Feature

Downloads

64

Readme

XPRMNTL

Feature-Client.js

Build Status NPM version Downloads Tips

This is a Node.js library for the consumption of XPRMNTL product.

var feature = require('feature-client');

feature.configure({
  devKey: 'put the XPRMNTL devkey for your app here',
  experiments: [  'testExp1', 'testExp2' ],
  shared: {
    devKey: 'put the XPRMNTL devkey for your shared app here',
    experiments: [ 'sharedExp1', 'sharedExp2' ]
  }
});

feature.cron('* * * * *', function(err, settings) {
  // Reload your settings into memory
});

// This step must be called last
feature.announce().then(function(settings) {
  // Load settings into memory; start your app
});

Installation

$ npm install feature-client

Configuration

Necessary components:

  • featureUrl
    • this is the URL to the XPRMNTL dashboard.
    • Defaults to process.env.FEATURE_URL.
  • devKey
    • this is the devKey generated for you by the XPRMNTL dashboard.
    • Defaults to process.env.FEATURE_DEVKEY
  • experiments
    • This is an array of all of your app-level experiments. These can be strings, objects, or a mixture of the two:
      • String: 'experimentName'
      • Object:
{
  name: 'experimentName',
  default: true,
  description: 'Here\'s my description of my experiment. This helps set context for anyone who wants to know what it is for.'
}
  • timeout
    • This is the number of milliseconds after which the request should time out.
    • May be disabled by setting to false or 0
    • Defaults to 5000 (5s)
  • shared
    • This object allows you to configure and accept configuration for a shared set of experiments. If, for example, you have a separate set of experiments for your site-wide theme, you would configure those here, shared among your applications.
    • This object has two properties:
      • devKey - The devKey for the shared experiment data
      • experiments - An array of shared experiments. Same format as app-level experiments.
  • reference
    • This string determines which "reference" is making the request.
    • If this value is sent, only that reference's configuration is sent back instead of all of them.
    • Currently supported: "local", "int" (integration), "beta", "prod"

Cron Job Subscription

Use of the cron allows you to refetch your configuration on whatever period you'd like.

feature.cron('* * * * *', function(err, settings) {
  // This calls every minute (5 stars)
  // Handle your re-configuration and errors here.
});
feature.cron('*/30 * * * * *', function(err, settings) {
  // This calls every 30 seconds
  // Handle your re-configuration and errors here.
});

feature.cron accepts two parameters:

  • cronTime
    • string in the Cron format. Since it uses node-cron, it also allows you to add an optional 6th item at the beginning for seconds
  • handler
    • This function should have an arity of 2 to accept an error and the new configuration settings, and it gets called on each refetch attempt.

Announcement

This step sends your configuration to the XPRMTNL dashboard to update and fetch the remote configuration. Any new experiments get registered and default either to false or to whatever you've set as your default for that experiment.

This is an asynchronous step that returns a Q.promise and/or accepts a callback:

feature.announce(function(err, data) {
  // Handle the configuration or failure here
});

feature.announce().then(function success(data) {
  // Handle the configuration here
}, function failure(resp) {
  // Handle failure here
  var err = resp[0];
  var defaults = resp[1];
);

In case of XPRMNTL failure, the defaults are returned.

Loading

In your development environment, when you're creating and working with new experiments, you will call announce whenever you start your application. If you're in a production environment, you no longer need to check to see if there are new experiments, so you need not send your full configuration to the server. In this case, you simply need to load.

The callback and/or handlers for load and announce are expected to work the same, but loading will only fetch the remote configuration, rather than potentially updating that information based on the configuration in this app. This can be a time-saver for your build process.

feature.load(function(err, data) {
  // Handle the configuration or failure here
});

feature.load().then(function success(data) {
  // Handle the configuration here
}, function failure(resp) {
  // Handle failure here
  var err = resp[0];
  var defaults = resp[1];
});