Skip to content
v1
Docs

Node.js SDK

WatchTower15 in Hono

Terminal window
npm install @watchtower15/sdk hono @hono/node-server

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

import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { Aggregator, WatchTower15 } from '@watchtower15/sdk';
const metrics = new Aggregator({ client: WatchTower15.fromEnvironment(), allowList: { 'orders.created': 'count' } });
const app = new Hono();
app.post('/orders', (c) => {
metrics.increment('orders.created');
return c.json({ created: true }, 201);
});
const server = serve({ fetch: app.fetch, port: 3000 });
server.on('close', () => {
void metrics.close();
});

On Node @hono/node-server gives the app no execution context (c.executionCtx throws), so waitUntil is not the form here: the aggregator is closed when the server serve() returns closes, as in the Express recipe.

On Cloudflare Workers the form is c.executionCtx.waitUntil(metrics.flush({ final: true })). It is documented here and not tested: Workers are not in the SDK’s test matrix. See Serverless.