Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "launchdarkly-node-server-sdk"

This is the API reference for the LaunchDarkly Server-Side SDK for Node.js.

In typical usage, you will call init once at startup time to obtain an instance of LDClient, which provides access to all of the SDK's functionality.

For more information, see the SDK reference guide.

Index

Type aliases

LDFlagValue

LDFlagValue: any

The types of values a feature flag can have.

Flags can have any JSON-serializable value.

LDLogLevel

LDLogLevel: "debug" | "info" | "warn" | "error" | "none"

Logging levels that can be used with basicLogger.

Set BasicLoggerOptions.level to one of these values to control what levels of log messages are enabled. Going from lowest importance (and most verbose) to most importance, the levels are 'debug', 'info', 'warn', and 'error'. You can also specify 'none' instead to disable all logging.

Functions

FileDataSource

  • Creates an object that allows you to use local files as a source of feature flag state, instead of connecting to LaunchDarkly. This would typically be used in a test environment.

    For more information about this feature, see the SDK features guide.

    To use this component, call FileDataSource(options) and store the result in the updateProcessor property of your LaunchDarkly client configuration:

    var dataSource = LaunchDarkly.FileDataSource({ paths: [ myFilePath ] });
    var config = { updateProcessor: dataSource };
    

    This will cause the client not to connect to LaunchDarkly to get feature flags, and use the file data instead.

    The client may still make network connections to send analytics events, unless you have disabled this in your configuration by setting LDOptions.sendEvents to false.

    The supported file formats are as follows:

    • JSON files in the format described in the SDK features guide are always supported.
    • The SDK can also read YAML files with an equivalent schema, if you explicitly install the yaml package in your application. This package is not installed by default, to avoid adding to the size of the SDK bundle for this rarely-used feature. The SDK is compatible with any version of the package that supports calling yaml.parse(string) with no custom options.

    Parameters

    • options: FileDataSourceOptions

      Configuration for the data source. You should at least set the paths property.

    Returns object

    An object to put in the updateProcessor property for LDOptions.

basicLogger

  • Provides a simple LDLogger implementation.

    This logging implementation uses a simple format that includes only the log level and the message text. Output is written to the standard error stream (console.error). You can filter by log level as described in BasicLoggerOptions.level.

    To use the logger created by this function, put it into LDOptions.logger. If you do not set LDOptions.logger to anything, the SDK uses a default logger that is equivalent to ld.basicLogger({ level: 'info' }).

    example

    This example shows how to use basicLogger in your SDK options to enable console logging only at warn and error levels.

      const ldOptions = {
        logger: ld.basicLogger({ level: 'warn' }),
      };
    
    example

    This example shows how to use basicLogger in your SDK options to cause log output to go to console.log instead of console.error.

      const ldOptions = {
        logger: ld.basicLogger({ destination: console.log }),
      };
    

    Parameters

    • Optional options: BasicLoggerOptions

      Configuration for the logger. If no options are specified, the logger uses { level: 'info' }.

    Returns LDLogger

init

  • Creates an instance of the LaunchDarkly client.

    Applications should instantiate a single instance for the lifetime of the application. The client will begin attempting to connect to LaunchDarkly as soon as it is created. To determine when it is ready to use, call LDClient.waitForInitialization, or register an event listener for the "ready" event using LDClient.on.

    Important: Do not try to instantiate LDClient with its constructor (new LDClient()); the SDK does not currently support this.

    Parameters

    • key: string

      The SDK key.

    • Optional options: LDOptions

      Optional configuration settings.

    Returns LDClient

    The new client instance.

Generated using TypeDoc