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

@harnessio/ff-nodejs-server-sdk

Package Overview
Dependencies
Maintainers
5
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harnessio/ff-nodejs-server-sdk

Feature flags SDK for NodeJS environments

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-16.84%
Maintainers
5
Weekly downloads
 
Created
Source

Harness Feature Flags Server SDK for NodeJS

TypeScript version Node.js version APLv2

Before you Begin

Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.

For more information, see https://harness.io/products/feature-flags/

To read more, see https://ngdocs.harness.io/category/vjolt35atg-feature-flags

To sign up, https://app.harness.io/auth/#/signup/

Getting Started

Setup

npm install @harnessio/ff-nodejs-server-sdk

Import the package (CommonJS)

const { Client } = require('@harnessio/ff-nodejs-server-sdk');

Import the package (ES modules)

import { Client } from '@harnessio/ff-nodejs-server-sdk';

Initialize

This is the most simple way to initialize SDK using only a server type key

const client = new Client('your server type SDK key');

Advanced initialization can be done using options

const client = new Client('your server type SDK key', {
  enableStream: false,
});

Define a target

const target = {
  identifier: 'harness',
  name: 'Harness',
  attributes: {}
};

Evaluate the flag with default value set to false

const value = await client.boolVariation('test', target, false);

Shutting down SDK

client.close();

Avaialable public methods

function boolVariation(
  identifier: string,
  target: Target,
  defaultValue: boolean = true,
): Promise<boolean>;
function stringVariation(
  identifier: string,
  target: Target,
  defaultValue: boolean = '',
): Promise<string>;
function numberVariation(
  identifier: string,
  target: Target,
  defaultValue: boolean = 1.0,
): Promise<number>;
function jsonVariation(
  identifier: string,
  target: Target,
  defaultValue: boolean = {},
): Promise<Record<string, unknown>>;
function close(): void;

Avaialable options

baseUrl: string;             // baseUrl is where the flag configurations are located
eventsUrl: string;           // eventsUrl is where we send summarized target events
pollInterval: number;        // pollInterval (default 60s)
eventsSyncInterval: number;  // Metrics push event (default 60s)
enableStream: boolean;       // enable server sent events
enableAnalytics: boolean;    // enable analytics
cache: KeyValueStore;        // set custom cache (default lru cache)
store: AsyncKeyValueStore;   // set custom persistent store (default file store)
logger: Logger;              // set logger (default console)

Singleton example

import CfClient from '@harnessio/ff-nodejs-server-sdk';

CfClient.init('your server type SDK key');

const FLAG_KEY = 'test_bool';
const target = {
  identifier: 'harness',
  name: 'Harness',
  attributes: {}
};
const defaultValue = false;

setInterval(async() => {
    const value = await CfClient.boolVariation(FLAG_KEY, target, defaultValue);
    console.log("Evaluation for flag test and target none: ", value);
}, 10000);

Wait for initialization example

const { Client } = require('@harnessio/ff-nodejs-server-sdk');

console.log('Starting application');
const client = new Client('1c100d25-4c3f-487b-b198-3b3d01df5794');
client
  .waitForInitialization()
  .then(() => {
    setInterval(async () => {
      const target = {
        identifier: 'harness',
      };
      const value = await client.boolVariation('test', target, false);
      console.log('Evaluation for flag test and target: ', value, target);
    }, 10000);

    console.log('Application started');
  })
  .catch((error) => {
    console.log('Error', error);
  });

License

Licensed under the APLv2.

FAQs

Package last updated on 19 Oct 2021

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