Varypilot/ DOCUMENTATION
Open app ↗

Integrations

Node.js SDK

Make a server-side assignment with an environment-scoped credential.

Keep credentials on the server

Download the Node.js module from the Integration section or the SDK URL. Create an environment-scoped server credential privately in Varypilot and store it in your server's secret manager. Never expose it through a public environment variable or client bundle.

Per-request client

javascript
import { createABServerClient } from "./node.mjs";
const ab = createABServerClient({
  projectKey: PUBLIC_PROJECT_KEY,
  environment: ENVIRONMENT_NAME,
  endpoint: "https://varypilot-edge-api.silva-pires-ricardo86.workers.dev",
  serverKey: process.env.VARYPILOT_SERVER_KEY,
  visitorId: STABLE_PSEUDONYMOUS_VISITOR_ID,
  url: REQUEST_URL,
  consent: ANALYTICS_CONSENT_GRANTED
});
try {
  await ab.init();
  const variant = ab.getVariant(EXPERIMENT_KEY, CONTROL_VARIANT_KEY);
  // Render the assigned experience before recording exposure.
  ab.trackExposure(EXPERIMENT_KEY, variant);
  await ab.flush();
} finally {
  await ab.close();
}

One visitor, consistent identity

Create and close a request-scoped client. Do not share a mutable visitor client between server requests or users. Use the same stable identifier when browser and server assignment need to agree.