Getting started with JavaScript SSR SDK

1 minute read

This section describes how to set up and install the JavaScript SSR SDK and how to deploy a feature flag.

Step 1 - Setting up

The following are prerequisites for installing the JavaScript SSR SDK:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key.

    • Get the key from App Settings > Environment > Key.

Step 2 - Installing the JavaScript SSR SDK

Add the CloudBees Feature Management JavaScript SSR library to your application by running the following npm commands:

# # Add JavaScript SSR SDK package as your application dependency
$ npm i rox-ssr --save

Add the following lines of code to your application:

// Import SDK
import { Flag, RoxString, RoxNumber, Rox } from 'rox-ssr';

// Create a Roxflag in the flags container class
const flags = {
  enableTutorial: new Flag(),
  titleColors: new RoxString('White', ['White', 'Blue', 'Green', 'Yellow']),
  titleSize: new RoxNumber(12, [14, 18, 24])

async function initRollout() {
  const options = {  }

  // Register the flags
  Rox.register('', flags);

  // Setup the key
  await Rox.setup('<ROLLOUT-ENV-KEY>', options);

  // Boolean flag example
  if (flags.enableTutorial.isEnabled()) {
    console.log('enableTutorial flag is true');
    // TODO:  Put your code here that needs to be gated

  // RoxString flag example
  console.log('Title color is ' + flags.titleColors.getValue());

  // RoxNumber flag example
  console.log('Title size is ' + flags.titleSize.getValue());

initRollout().then(function() {
  console.log('Done loading Rollout');

Container class registration and environment key setup

  • You cannot call Rox.setup() twice in the same runtime.

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.