Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

featuretoggle-client-node

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

featuretoggle-client-node

feature toggle client for node

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

featuretoggle-client-node

A node client to retrieve feature toggles stored in Etcd.

Build Status

NPM

Installation

npm install featuretoggle-client-node

Usage

var Client = require('featuretoggle-client-node');

var client = new Client("application-name", {
    etcdHost: "127.0.0.1",
    etcdPort: 4001,
    cacheIntervalMs: 60000
});

client.on("error", function(err) {
    console.log(err);
});

client.on("initialized", function() {
    
    client.get("toggle1", function(err, value) {
        console.log(value);
    });
    
    client.getOrDefault("toggle2", true, function(err, value) {
        console.log(value);
    });

});

Important Note

The "error" event must be subscribed to, otherwise errors will cause the application to exit

client.on("error", function(err) { });

Etcd

Feature toggles are stored in Etcd using the following convention: http://host:port/v2/keys/v1/toggles/applicationName/toggleName

API

Client(applicationName, [config])

Creates a new feature toggle client

var Client = require("featuretoggle-client-node");
var client = new Client("application-name", { etcdHost: "127.0.0.1" });
  • applicationName the name of the application used to find feature toggles
  • config (optional)
    • etcdHost (default: "127.0.0.1")
    • etcdPort (default: 4001)
    • cacheIntervalMs interval for the cache update, which loads all the applications toggles into memory (default: 60000)

.on(eventName, callback)

Subscribs to events emitted by the client.

  • error [required]
  • initialized
  • updating-cache
  • updated-cache

.get(toggleName, callback)

Gets the value of a feature toggle (true or false) if exists, otherwise return null

  • toggleName the name of the toggle, used with the application name to get the feature toggle value
  • callback function with parameters (err, value)

.getOrDefault(toggleName, defaultValue, callback)

Gets the value of a feature toggle (true or false) if exists, otherwise return the default value (true or false)

  • toggleName the name of the toggle, used with the application name to get the feature toggle value
  • defaultValue the value to return if the toggle value is not found or if there is an error
  • callback function with parameters (err, value)

FAQs

Package last updated on 09 Jul 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc