No results for ""
EXPAND ALL
  • Home
  • API docs

Node.js (server-side) SDK 7.x to 8.0 migration guide

Read time: 6 minutes
Last edited: Oct 03, 2024

Overview

This topic summarizes changes and explains how to adapt code that uses a 7.x version of the Node.js (server-side) SDK to use version 8.0 or later.

Version 8.0 includes several breaking changes.

Before you migrate to version 8.0, update to the latest 7.x version. Some of the changes that are mandatory in 8.0 were originally added in a 7.x version and made optional.

Introducing @launchdarkly/node-server-sdk

In version 8.0, we've introduced @launchdarkly/node-server-sdk as a replacement for launchdarkly-node-server-sdk.

In this new package, the Node.js (server-side) SDK:

  • has been re-written in Typescript.
  • has been moved to a new repository in GitHub.
  • has a new package name.

Most of the API has remained compatible with version 7.x.

Identifying Node.js versions for the 8.0 SDK

The 8.0 version of the SDK is compatible with Node.js versions 14 and higher. LaunchDarkly no longer supports older Node.js versions, as is documented in the End of Life policy.

LaunchDarkly also no longer supports some Node.js versions above 14 that are not long-term-support versions and have reached their end of life. To learn more, read the Node.js releases page.

Understanding changes to configuration options

The userKeysCapacity and userKeysFlushInterval were deprecated in 7.x and removed in 8.0. Use contextKeysCapacity and contextKeysFlushInterval instead.

The proxyHost, proxyPort, and proxyAuth options were removed in 8.0. Use proxyOptions instead.

Here's how:

import * as ld from '@launchdarkly/node-server-sdk';
const options: ld.LDOptions = {
proxyOptions: {
host: 'your-proxy-host',
port: 8080,
scheme: 'https',
auth: 'username:password'
}
};

To learn more, read Web proxy configuration.

Understanding changes to the Redis integration

The Redis integration package has a new repository and package.

Node.js (server-side) SDK 8.0 does not work with the 2.x or earlier version of the integration. It requires @launchdarkly/node-server-sdk-redis version 3.0 or higher.

In version 3.0 and higher of the Node.js SDK Redis integration, the ioredis package is used for Redis operations.

In version 3.0 the redisOpts setting of LDRedisOptions is the RedisOptions type from ioredis. If you were using this option, then be sure to migrate your redis settings to ioredis settings.

In version 3.0 the client setting of LDRedisOptions is the Redis type from ioredis. If you were using this option, then be sure to create an ioredis client instead of a redis client.

Basic configuration of the Redis integration:

const ld = require('@launchdarkly/node-server-sdk');
const RedisFeatureStore = require('@launchdarkly/node-server-sdk-redis');
const store = RedisFeatureStore({
redisOpts: { host: 'redis-host', port: 6379 },
prefix: 'your-key-prefix',
cacheTTL: 30,
});
const options = {
featureStore: store
};
const client = ld.init(sdkKey, options);

Understanding changes to the DynamoDB integration

The DynamoDB integration package has a new repository and package.

Node.js (server-side) SDK 8.0 does not work with the 4.x or earlier version of the integration. It requires @launchdarkly/node-server-sdk-dynamodb version 5.0 or higher.

In version 5.0 and higher of the Node.js SDK DynamoDB integration, the AWS SDK for JavaScript v3 package is used for DynamoDB operations.

In version 5.0 the clientOptions setting of LDDynamoDBOptions is the DynamoDBClientConfig from @aws-sdk/client-dynamodb. If you were using this options, then be sure to migrate your settings to those used in the AWS SDK for JavaScript v3.

In version 5.0 the dynamoDBClient setting of LDDynamoDBOptions is the DynamoDBClient from @aws-sdk/client-dynamodb. If you were using this options, then be sure to migrate your client the version from the AWS SDK for JavaScript v3.

Basic configuration of the DynamoDB integration:

const ld = require('@launchdarkly/node-server-sdk');
const { DynamoDBFeatureStore } = require('@launchdarkly/node-server-sdk-dynamodb');
const store = DynamoDBFeatureStore(
'your-table',
{ cacheTTL: 30 }
);
const options = {
featureStore: store
};
const client = ld.init('sdk-key-123abc', options);

Understanding changes to the TestData integration

In v8.0 the API for TestData has changed:

  • TestData is now a class, and you must construct it using new.
  • There is a new method, getFactory, to get the updated processor factory.

Here's how:

const { TestData } = require('@launchdarkly/node-server-sdk/integrations');
const td = TestData();
testData.update(td.flag('flag-key-123abc').booleanFlag().variationForAllUsers(true));
const client = new LDClient('sdk-key-123abc', { updateProcessor: td.getFactory() });
// flags can be updated at any time:
td.update(td.flag('flag-key-456def')
.variationForUser('user-key-123abc', true)
.fallthroughVariation(false));

Understanding changes to the FileData integration

In v8.0 the API for FileDataSource API has changed:

  • FileDataSourceFactory is now a class, and you must construct it using new.
  • There is a new method, getFactory, to get the updated processor factory.

Here's how:

const ld = require('@launchdarkly/node-server-sdk');
const { FileDataSourceFactory } = require('@launchdarkly/node-server-sdk/integrations');
const fileData = new FileDataSourceFactory({
paths: [ 'file1.json', 'file2.json' ]
});
const options = {
updateProcessor: fileData.getFactory()
};
const client = ld.init('sdk-key-123abc', options);