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

@devcycle/nodejs-server-sdk

Package Overview
Dependencies
Maintainers
6
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devcycle/nodejs-server-sdk

The DevCycle NodeJS Server SDK used for feature management.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

DevCycle NodeJS Server SDK

The NodeJS Server SDK for DevCycle.

This SDK uses local bucketing to perform all user segmentation and bucketing locally in the SDK, providing immediate responses to variable and feature requests for a user. The SDK will download the latest version of your DevCycle environments configuration from a CDN on initialization, and will periodically poll the CDN for configuration changes.

Installation

Our library can be found on npm and installed by the following:

npm install @devcycle/nodejs-server-sdk

Usage

To use the DVC Server SDK in your project, import the @devcycle/nodejs-server-sdk package and call initialize with your DVC environment server key. You may optionally await for the client to be initialized.

JS Example:

const DVC = require('@devcycle/nodejs-server-sdk')

const dvcClient = await DVC.initialize('<DVC_ENVIRONMENT_SERVER_KEY>').onClientInitialized()

Typescript Example:

import { initialize } from '@devcycle/nodejs-server-sdk'

const dvcClient = await initialize('<DVC_ENVIRONMENT_SERVER_KEY>').onClientInitialized()

Initialization Options

The SDK exposes various initialization options which can be set on the initialization() method:

const dvcClient = await DVC.initialize('<DVC_ENVIRONMENT_SERVER_KEY>', {
        configPollingIntervalMS: 60 * 1000 
    }).onClientInitialized()
DVC OptionDescription
configPollingIntervalMSControls the polling interval in milliseconds to fetch new environment config changes, defaults to 10 seconds, minimum value is 1 second.
configPollingTimeoutMSControls the request timeout to fetch new environment config changes, defaults to 5 seconds, must be less than the configPollingIntervalMS value, minimum value is 1 second.
flushEventsMSControls the interval between flushing events to the DevCycle servers, defaults to 30 seconds.
disableEventLoggingDisables logging of any events or user data to DevCycle.

User Object

The full user data must be passed into every method. The only required field is the user_id. The rest are optional and are used by the system for user segmentation into variables and features.

const user = {
    user_id: 'user1@devcycle.com',
    name: 'user 1 name',
    customData: {
        customKey: 'customValue'
    }
}
const variable = dvcClient.variable(user, 'test-feature', false)

Using Variables

To get values from your Variables, dvcClient.variable() is used to fetch variable values using the user data, variable key, coupled with a default value for the variable. The default variable will be used in cases where the user is not segmented into a feature using that variable, or the project configuration is unavailable to be fetched from DevCycle's CDN.

The default value can be of type string, boolean, number, or object.

const variable = dvcClient.variable(user, 'YOUR_VARIABLE_KEY', false)
if (variable.value) {
    // Feature Flag on
}

Grabbing All Variables

To grab all the segmented variables for a user:

const variables = dvcClient.allVariables(user)

Getting All Features

You can fetch all segmented features for a user:

const features = dvcClient.allFeatures(user)

FAQs

Package last updated on 22 Apr 2022

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