• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Node.js (client-side) SDK 1.x to 2.0 migration guide

    Read time: 2 minutes
    Last edited: Sep 19, 2022

    Overview

    This topic explains how to adapt code that currently uses a 1.x version of the Node.js client-side SDK to use version 2.0 or later.

    The changes in this release are mainly to update the SDK's platform compatibility and remove an unnecessary third-party dependency. The release does not change any existing APIs, and adds no new functionality except in the area of logging.

    Before you migrate to 2.0, update to the latest 1.x version. To learn more about updating to the latest 1.x version, visit the SDK's GitHub repository.

    Identifying Node.js versions for the 2.0 SDK

    The 1.x version of the SDK is compatible with Node.js versions 12 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 12 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 dependencies

    The SDK no longer has a dependency on the winston logging package. You can still use winston, but the SDK does not load it by default. To learn more, read Understanding changes to logging.

    Understanding changes to logging

    Previously, if you did not specify your own logger in the logger property, the SDK used winston to create a logger.

    In versions 2.0 and higher of the SDK, if you do not specify your own logger, the SDK writes log output directly to the console. It uses the same format that it was previously using with winston, so you may not notice any difference.

    If you want to use winston, you can still create a winston logger and put it in the SDK's logger property. This works exactly the same as before. The only difference is that you must make sure winston exists as a dependency in your project, instead of the dependency being provided automatically by the SDK.

    The SDK also has a new option to allow configuring a simple logger without using winston. To learn more, read basicLogger. This replaces the previous createConsoleLogger, which had slightly different parameters. If you were calling ld.createConsoleLogger('warn'), you would change that to ld.basicLogger({ level: 'warn' }).

    Understanding what was deprecated

    All types and methods that were marked as deprecated/obsolete in the last 1.x release have been removed from the 2.0 release. If you were using these with a recent version previously, you should already have received deprecation warnings at build time or runtime, with suggestions about their recommended replacements.