This section describes how to set up and install the Node.js SDK and how to deploy a feature flag.
Step 1 - Setting up
The following are prerequisites for installing the Node.js SDK:
-
Create a CloudBees Feature Management account. See Signup Page to create an account.
-
Get your environment key. Copy your environment key from App settings > Environments > Key.
Step 2 - Installing the Node.js SDK
Add the CloudBees Feature Management Node.js library to your application by running the
following npm
commands:
# # Add node.js SDK package as your application dependency $ npm i rox-node --save # For TypeScript projects, also add the corresponding types: npm i @types/rox-node --save
Add the following lines of code to your application:
> ES6
CommonJS/AMD
import Rox from 'rox-node'; const flags = { enableTutorial: new Rox.Flag(), titleColors: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']), titleSize: new Rox.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'); });
const Rox = require('rox-node'); const flags = { enableTutorial: new Rox.Flag(), titleColors: new Rox.RoxString('White', ['White', 'Blue', 'Green', 'Yellow']), titleSize: new Rox.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
|