Skip to content

SDKs

Node.js SDK

Send server-side events, evaluate feature flags locally and capture backend errors with the Tracklyne Node.js SDK.

Install

Terminal
npm install @tracklyne/node
server.ts
import { Tracklyne } from "@tracklyne/node";

const tl = new Tracklyne("tl_your_project_token", {
  host: "https://tracklyne.com",
  personalApiKey: process.env.TL_PERSONAL_KEY, // local flag evaluation
});

tl.capture({ distinctId: user.id, event: "invoice paid", properties: { amount: 120 } });

if (await tl.isFeatureEnabled("new-billing", user.id)) {
  // ship it to this user
}

await tl.shutdown(); // flush before the process exits

Events are batched in memory and sent every 10 seconds or every 20 events, gzip-compressed and retried on network errors. Call shutdown() before a script exits, or flush() at the end of each serverless invocation, so nothing is lost. The SDK never throws: listen with tl.on("error", …).

server.ts
tl.identify({ distinctId: "user_42", properties: { $set: { email: "ana@acme.tn", plan: "pro" } } });
tl.groupIdentify({ groupType: "company", groupKey: "acme", properties: { seats: 40 } });

Use the same id as the browser

Server events need a distinctId. Use your user id, the one you pass to identify in the browser, so front-end and back-end events join the same person.

Local flag evaluation

With a personalApiKey, the SDK downloads flag definitions every 30 seconds and evaluates them in-process: no network call per request, and the result matches the browser exactly (the hashing is the same).

server.ts
const variant = await tl.getFeatureFlag("pricing-test", user.id, {
  personProperties: { plan: user.plan },
});

Local evaluations do not count toward your flag request quota.

Errors

server.ts
try {
  await work();
} catch (err) {
  tl.captureException(err, "user_42", { route: "/checkout" });
}