Browse docs

Explore by section, then jump directly into a page.

Express SDK

Use the FlashAnalytics Express SDK to automatically track requests and server errors.

The Express package provides request and error middleware plus a shared SDK instance on req.fa.

Install

npm install @flash-analytics/express@2.1.5
pnpm add @flash-analytics/express@2.1.5

Recommended setup

import express from 'express';
import { createFlashAnalytics } from '@flash-analytics/express';

const app = express();

const { requestMiddleware, errorMiddleware } = createFlashAnalytics({
  clientId: 'YOUR_APP_ID',
  clientSecret: 'YOUR_SECRET_KEY',
  endpoint: 'https://api.flashanalytics.app',
});

app.use(requestMiddleware);
app.use(errorMiddleware);

You can also use createMiddleware() and createErrorMiddleware() separately.

Auto-captured events

  • request for captured HTTP requests
  • server_error for errors passed to Express error middleware

Useful options

  • resolveUserId(req) to attach a profile id
  • shouldCaptureExpressRequest(req) to skip paths like /health
  • shouldCaptureError(err, req) to suppress expected errors
  • debug, onTrackSuccess, and onTrackError for operational visibility

Manual tracking via req.fa

app.post('/checkout', (req, res) => {
  req.fa.track('checkout_started', {
    cartValue: req.body.total,
    itemCount: req.body.items.length,
  });

  res.json({ ok: true });
});

Session access

app.get('/session', (req, res) => {
  const session = req.fa.getSession();
  res.json({ sessionId: session?.id });
});