Hyphen

Node.js

A guide to using the Hyphen Node.js SDK for server-side integration with Hyphen services like Toggle feature flags and Net.Info.

The @hyphen/sdk is Hyphen's native server-side Node.js SDK. It provides a single client for working with Hyphen services — including Toggle feature flags and Net.Info — from backend services, APIs, and server-rendered applications.

Table of Contents

Installation

npm install @hyphen/sdk

Authentication

The SDK authenticates with your project public key (it starts with public_) and your application id. See Get a Project's Public Key for where to find these in the Hyphen dashboard.

You can pass them directly or provide them via environment variables:

HYPHEN_PUBLIC_API_KEY=public_your_api_key
HYPHEN_APPLICATION_ID=your_application_id

Initialization

import { Hyphen } from '@hyphen/sdk';

const hyphen = new Hyphen({
  publicApiKey: 'public_your_api_key',
  applicationId: 'your_application_id',
});

Usage

Evaluate a boolean feature flag, falling back to a default value if it can't be resolved:

const enabled = await hyphen.toggle.getBoolean('hyphen-sdk-boolean', false);

if (enabled) {
  // Execute new feature code
}

See also