JavaScript SDK
For browser based web applications.

Installation

1
npm add @featureboard/js-sdk
2
# Or
3
yarn add @featureboard/js-sdk
4
# Or
5
pnpm add @featureboard/js-sdk
Copied!

Getting started

1
const { client, close } = await FeatureBoardService.init('env-api-key', ['audiences', 'of', 'user'], {
2
/* options */
3
})
4
5
const featureValue = client.getFeatureValue('my-feature-key', fallbackValue)
6
7
const unsubscribe = subscribeToFeatureValue('my-feature-key', fallbackValue, (onValue) => {
8
// Will be called with the initial value and subsiquent updates
9
})
10
11
// Remove subscription
12
unsubscribe()
Copied!
NOTE: You must specify a fallback value, this value is used when the feature is unavailable in the current environment.

Options

The optional third argument to init

initialValues

Provides the SDK with a set of initial flag values, if provided the subscription and update of the feature state will happen in the background. Allowing you to immediately use the SDK

updateStrategy

Configure how the FeatureBoard SDK gets updated values, default 'live'
live
Connects to the FeatureBoard service using web sockets, giving near realtime updates
polling
Polls for updates using http. Default polling interval 30 seconds.

manual

If you would like to control when feature state is updated, or not have updates just choose 'manual'
1
const { client, updateFeatures } = await FeatureBoardService.init('env-api-key', ['audiences', 'of', 'user'], {
2
updateStrategy: 'manual',
3
/* options */
4
})
5
6
// Triggers an update of the feature state
7
updateFeatures()
Copied!

TypeScript

To get type safety on your features you can use Declaration Merging to define the features
1
declare module '@featureboard/js-sdk' {
2
interface Features {
3
'my-feature-key': string
4
}
5
}
Copied!