Home / Developers / JavaScript and TypeScript

Quickstart by stack

JavaScript and TypeScript Quickstart

Install the JavaScript SDK, evaluate a flag in Node.js or the browser, and add context, defaults, and usage reporting in one pass.

Prerequisites

  • Node.js 16+ for server-side usage or a modern browser build pipeline.
  • A server key for Node.js and a client key for browser usage, both stored in configuration and not committed to source.
  • One flag key you can safely evaluate in a non-production environment.
Install bash

npm install @zenmanage/sdk
Node.js initialization typescript

import { Zenmanage, ConfigBuilder, Context, Attribute } from '@zenmanage/sdk';

const zenmanage = new Zenmanage(
  ConfigBuilder.create()
    .withEnvironmentToken(process.env.ZENMANAGE_SERVER_KEY!)
    .build()
);

const context = new Context('user', 'Jane Doe', 'usr_123', [
  new Attribute('country', ['US']),
  new Attribute('plan', ['enterprise']),
]);

const flag = await zenmanage.flags().withContext(context).single('new-checkout', false);
console.log(flag.isEnabled());
Browser pattern typescript

import { Zenmanage, ConfigBuilder, Context } from '@zenmanage/sdk';

const zenmanage = new Zenmanage(
  ConfigBuilder.create()
    .withEnvironmentToken(import.meta.env.VITE_ZENMANAGE_CLIENT_KEY)
    .build()
);

const context = Context.single('user', currentUser.id, currentUser.name);
const theme = await zenmanage.flags().withContext(context).single('checkout-theme', 'classic');

document.documentElement.dataset.checkoutTheme = theme.asString();

TypeScript support

The SDK is written in TypeScript and exports its types. That means your application can type configuration, context data, and flag access patterns without custom declarations.

Safe defaults and usage reporting

Pass an inline default to single() or use a defaults collection when many flags need fallbacks. The JavaScript SDK also supports usage reporting so evaluation activity can be recorded without manual API calls.

Defaults and explicit usage reporting typescript

const variant = await zenmanage.flags().single('landing-page-variant', 'control');
await zenmanage.flags().reportUsage('landing-page-variant');
console.log(variant.asString());

Next step

Take the next integration step in your own stack.

Start with the quickstart that matches your runtime, then return to the reference pages when you need exact request and payload details.