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

configcat-common

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

configcat-common

ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
114K
decreased by-0.31%
Maintainers
1
Weekly downloads
 
Created
Source

ConfigCat SDK for node.js

ConfigCat is a cloud based configuration as a service. It integrates with your apps, backends, websites, and other programs, so you can configure them through this website even after they are deployed. https://configcat.com

Build Status codecov Known Vulnerabilities License
NPM

Getting Started

  1. Install NPM package: configcat-client-node
 npm i configcat-client-node
  1. Get your Api Key from configcat.com portal: API-KEY

  2. Create a ConfigCatClient instance:

var configcat = require("configcat-client-node");

var client = configcat.createClient("#YOUR-API-KEY#");
  1. Get your config value:
client.getValue("isMyAwesomeFeatureEnabled", false, {identifier : "userIdentifier"}, (value) => {
    if(value) {
        //show your awesome feature to the world!
    }
});

Configuration

Client supports three different caching policies to acquire the configuration from ConfigCat. When the client downloads the latest configuration, puts it into the internal cache and serves any configuration acquisition from cache. With these caching policies you can manage your configurations' lifetimes easily.

Auto polling (default)

Client downloads the latest configuration and puts into a cache repeatedly. Use pollingIntervalSeconds parameter to manage polling interval. You can subscribe to the configChanged event to get notification about configuration changes.

Lazy loading

Client downloads the latest configuration only when it is not present or expired in the cache. Use cacheTimeToLiveSeconds parameter to manage configuration lifetime.

Manual polling

With this mode you always have to invoke .forceRefresh() method to download a latest configuration into the cache. When the cache is empty (for example after client initialization) and you try to acquire any value you'll get the default value!


Configuration parameters are different in each mode:

Base configuration

PropertyNameDescriptionDefault
apiKeyApi Key to access your configuration.REQUIRED
logger'winston' logger instanceno default tracing method

Auto polling

PropertyNameDescriptionDefault
pollIntervalSeconds Polling interval in seconds.60
maxInitWaitTimeSecondsMaximum waiting time between the client initialization and the first config acquisition in seconds5
configChangedevent accessor to get notification about configuration changes-

Lazy loading

PropertyNameDescriptionDefault
cacheTimeToLiveSecondsUse this value to manage the cache's TTL.60

Example - increase CacheTimeToLiveSeconds to 600 seconds

var config = {
    "cacheTimeToLiveSeconds": 600
};

var client = configcat.createClientWithLazyLoad("#YOUR-API-KEY#", config);

Example - configChanged

In Auto polling mode you can subscribe an event to get notification about changes. We use "events" package to support event handling in our package.

var events = require("events");

var config = {    
    "configChanged": new events.EventEmitter()
};

config.configChanged.on(configcat.CONFIG_CHANGED_EVENT, () => console.log("config changed, update UI!"));

var client = configcat.createClientWithAutoPoll("#YOUR-API-KEY#", config);

Members

Methods

NameDescription
getValue(key: string, defaultValue: any, user: User, callback: (value: any) => void): void;Returns the value of the key
forceRefresh(callback: () => void): voidFetches the latest configuration from the server. You can use this method with WebHooks to ensure up to date configuration values in your application.

User object

If you want to get advantage from our percentage rollout and targeted rollout features, you should pass a user object to the getValue(key: string, defaultValue: any, user: user, callback: (value: any) => void) calls. We strongly recommend you to pass the user object in every call so later you can use these awesome features without rebuilding your application.

User

ParameterNameDescriptionDefault
identifierMandatory, unique identifier for the User or Session. e.g. Email address, Primary key, Session IdREQUIRED
email Optional parameter for easier targeting rule definitionsNone
countryOptional parameter for easier targeting rule definitionsNone
customOptional dictionary for custom attributes of the User for advanced targeting rule definitions. e.g. User role, Subscription type.None

Example simple user object:

var myUser = {
    identifier : "435170f4-8a8b-4b67-a723-505ac7cdea92"
};   

Example user object with optional custom attributes:

var myUser = {
    identifier : "435170f4-8a8b-4b67-a723-505ac7cdea92",
    email : "readme.user@configcat.com",
    country : "United Kingdom",
    custom : {
        "SubscriptionType": "Pro"
    }
};

Lifecycle of the client

We're recommend to use client as a singleton in your application.

Logging

We use Winston for logging you can setup with 'logger' attribute.

var config = {
    "logger": new winston.Logger({
            level: "info",
            transports: [
                new winston.transports.Console({ timestamp: true })
            ]})
};

License

MIT

Keywords

FAQs

Package last updated on 08 Nov 2018

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