# WatchTower15 in Fastify

```sh
npm install @watchtower15/sdk @watchtower15/pino fastify
```

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

```js
import Fastify from 'fastify';
import { Aggregator, WatchTower15 } from '@watchtower15/sdk';

const metrics = new Aggregator({ client: WatchTower15.fromEnvironment(), allowList: { 'orders.created': 'count' } });

const app = Fastify({
  logger: {
    transport: {
      targets: [
        { target: 'pino/file', options: { destination: 1 } },
        { target: '@watchtower15/pino', options: { stream: 'orders-api' } },
      ],
    },
  },
});

app.addHook('onClose', async () => {
  await metrics.close();
});
app.post('/orders', async (_request, reply) => {
  metrics.increment('orders.created');
  return reply.code(201).send({ created: true });
});
```

-   **Logs.** Fastify uses pino, so `@watchtower15/pino` is a second target beside the one that writes to standard output; it reads `WT15_LOGS_TOKEN` and runs in pino’s worker thread. See [Logs](https://developer.watchtower15.com/sdks/node/logs/).
-   **Metrics.** The `onClose` hook closes the aggregator, which sends what was counted.

Source: https://developer.watchtower15.com/sdks/node/fastify/
