Skip to main content

Node.js Quickstart

Use Xaiku on the server to fetch variants and track events from backend code.

Prerequisites

  • Node.js 20+
  • A Xaiku account with a public key (pk_*)
  • A experiment created in the Xaiku dashboard

1. Install

npm install @xaiku/node

2. Initialize the SDK

The Node.js factory is async — it fetches experiment variants during initialization.

import xaiku from '@xaiku/node'

const sdk = await xaiku({
pkey: 'pk_your_public_key',
experimentIds: ['your_experiment_id'],
})

Options

OptionTypeDefaultDescription
pkeystringYour public key (required).
experimentIdsstring[][]Experiment IDs to fetch variants for.
storeobject{ name: 'memory' }Storage backend. Always memory on the server.
onReportfunctionnullCallback with event buffer on flush.

Next steps