Set up Node.js (server-side) SDK

Install the package

$yarn add @launchdarkly/node-server-sdk

Initialize the SDK

Node.js (server-side) SDK initialization
1import * as LaunchDarkly from '@launchdarkly/node-server-sdk';
2
3// Set your LaunchDarkly SDK key.
4// This is inlined as example only for onboarding.
5// Never hardcode your SDK key in production.
6const client = LaunchDarkly.init('YOUR_SDK_KEY');
7
8// A "context" is a data object representing users, devices, organizations, and other entities.
9// You'll need this later, but you can ignore it for now.
10const context = {
11 kind: 'user',
12 key: 'EXAMPLE_CONTEXT_KEY',
13 email: 'biz@face.dev',
14};
15
16client.once('ready', function () {
17 // For onboarding purposes only we flush events as soon as
18 // possible so we quickly detect your connection.
19 // You don't have to do this in practice because events are automatically flushed.
20 client.flush();
21 console.log('SDK successfully initialized!');
22});

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client in the Node.js (server-side) SDK reference guide.