Skip to content
v1
Docs

Node.js SDK

WatchTower15 in Express

Terminal window
npm install @watchtower15/sdk express

This recipe is the app in the SDK’s examples/express/, which the SDK’s test suite runs on Node 24 against the test fakes.

import express from 'express';
import { Aggregator, WatchTower15 } from '@watchtower15/sdk';
const client = WatchTower15.fromEnvironment();
const metrics = new Aggregator({ client, allowList: { 'orders.created': 'count' } });
const app = express();
app.post('/orders', (_req, res) => {
metrics.increment('orders.created');
res.status(201).json({ created: true });
});
const server = app.listen(3000);
server.on('close', () => {
void metrics.close();
});
  • One client per process. The client holds the credentials and the connection settings; build it once.
  • An allow-list names every key you count. A key not listed is never counted.
  • Close on shutdown. server.close() ends the server, and its close event closes the aggregator, which sends what was counted and the open minute with it.

See Custom metrics and Testing your integration.