# Node.js analytics

> Live analytics for Node.js, Bun, Deno and Workers: middleware for Express, Fastify and Hono sends crawler visits, 404s, errors, response times and your events.

Source: https://status.mettr.app/integrations/node

## One middleware

```bash
npm install @mettr/node
```

```js
import { Mettr } from '@mettr/node';
import { mettrMiddleware } from '@mettr/node/express';

const mettr = new Mettr();

app.use(mettrMiddleware(mettr, { user: (req) => req.user?.id?.toString() }));
```

Fastify and Hono have theirs; anything that speaks `fetch` (Bun, Deno, Cloudflare Workers, Vercel's edge) wraps its handler in `withMettr`. It reads `METTR_SECRET_KEY` and `METTR_PUBLIC_KEY`, and sends only when `NODE_ENV` is `production`.

## What it sends on its own

- **Crawler visits**, with their page and status: search engines and AI crawlers seldom run the [browser script](/docs/browser-script), so only your server sees them.
- **404s** of people, as errors.
- **Exceptions**, by their class only, never the message.
- **Response times** of one request in twenty, by route.
- **The browser script**, served from `/_live` on your own domain with `mettr.scriptTag()`: page views and who is online, past most ad blockers, each event carrying the visitor and user your server saw.

## Your own events

```js
mettr.event('signup', { plan: 'pro' }, { userId: '42' });
```

Events wait a second to go together and are sent off the request's path. Sending never throws into your app.

## Revenue, history and deploys

Billing of your own? `mettr.subscription()` sends each subscription as it changes, and mettr works out [MRR, churn and revenue by source](/features/revenue). `mettr.import()` brings your history, and `mettr.annotation()` marks a [deploy](/docs/deploys) under the traffic chart.

## Open source

`@mettr/node` is MIT licensed, on [GitHub](https://github.com/mettrhq/mettr-js) and [npm](https://www.npmjs.com/package/@mettr/node), with no dependencies. [The full guide](/docs/node).
