Skip to main content

Node — Initialization

Install @signal-js/node and create one client with createSignalNode(). Use it in plain Node.js http/https servers or in Express. Reuse the same client across all requests.

Installation

npm install @signal-js/node

Using with Node.js

Create the client at startup and a helper to read tracing headers from http.IncomingMessage:
import http from 'http';
import { createSignalNode } from '@signal-js/node';

const signal = createSignalNode({
  apiKey: process.env.SIGNAL_API_KEY!,
  projectId: process.env.SIGNAL_PROJECT_ID!,
  // endpoint is optional (defaults to https://api.trysignal.ai/)
});

function getSessionInfo(req: http.IncomingMessage) {
  const headers = req.headers;
  return {
    sessionId: headers['x-signal-session-id'] as string | undefined,
    windowId: headers['x-signal-window-id'] as string | undefined,
    distinctId: headers['x-signal-distinct-id'] as string | undefined,
  };
}

const server = http.createServer(async (req, res) => {
  const { sessionId, windowId, distinctId } = getSessionInfo(req);
  // Use signal.capture(), signal.identify(), etc. with sessionId, windowId, distinctId
});

server.listen(3000);

Using with Express

Same client; read headers from req.headers:
import express from 'express';
import { createSignalNode } from '@signal-js/node';

const app = express();
app.use(express.json());

const signal = createSignalNode({
  apiKey: process.env.SIGNAL_API_KEY!,
  projectId: process.env.SIGNAL_PROJECT_ID!,
  // endpoint is optional (defaults to https://api.trysignal.ai/)
});

function getSessionInfo(req: express.Request) {
  return {
    sessionId: req.headers['x-signal-session-id'] as string | undefined,
    windowId: req.headers['x-signal-window-id'] as string | undefined,
    distinctId: req.headers['x-signal-distinct-id'] as string | undefined,
  };
}

// Use signal and getSessionInfo in routes
Create one createSignalNode() instance per process and reuse it. For session correlation, the client must send tracing headers; see Vue or React for addTracingHeaders.

Next steps