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
- pnpm
- yarn
npm install @xaiku/node
pnpm add @xaiku/node
yarn add @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
| Option | Type | Default | Description |
|---|---|---|---|
pkey | string | — | Your public key (required). |
experimentIds | string[] | [] | Experiment IDs to fetch variants for. |
store | object | { name: 'memory' } | Storage backend. Always memory on the server. |
onReport | function | null | Callback with event buffer on flush. |
Next steps
- Server-side Usage — patterns for Express, Fastify, etc.
- @xaiku/node reference — full API