# Node.js SDK

The Node.js SDK calls the [WatchTower15 API](https://developer.watchtower15.com/), counts what your application does as [custom metrics](https://docs.watchtower15.com/metrics/sources/) and ships its logs to [log ingest](https://docs.watchtower15.com/logs/custom-sources/), from one `WatchTower15` client. It builds, retries and batches the calls for you, and turns every failure into a typed error. It has no runtime dependency, uses `fetch`, and ships ES modules, CommonJS and TypeScript declarations.

## What it covers

-   **The REST API.** Every `/v1` operation is a method on a resource: `wt15.servers.list()`, `wt15.incidents.acknowledge(uuid)`. See [the REST API](https://developer.watchtower15.com/sdks/node/api/).
-   **Custom metrics.** Push points, or count in the request path with the aggregator and let a flush send them once a minute. See [custom metrics](https://developer.watchtower15.com/sdks/node/metrics/).
-   **Logs.** A logger, a pino transport and a winston transport that send lines to log ingest. See [logs](https://developer.watchtower15.com/sdks/node/logs/).

## Which package to install

| You use | Install | Page |
| --- | --- | --- |
| Anything | `npm install @watchtower15/sdk` | this page |
| pino | `npm install @watchtower15/pino` | [Logs](https://developer.watchtower15.com/sdks/node/logs/) |
| winston | `npm install @watchtower15/winston` | [Logs](https://developer.watchtower15.com/sdks/node/logs/) |
| NestJS 11 or 12 | `npm install @watchtower15/nestjs` | [NestJS](https://developer.watchtower15.com/sdks/node/nestjs/) |

The integrations require the core, `@watchtower15/sdk`, as a peer, so install both. All four packages are released together, at one version. For Express, Fastify, Hono and Next.js there is no package, only a tested recipe: [Express](https://developer.watchtower15.com/sdks/node/express/), [Fastify](https://developer.watchtower15.com/sdks/node/fastify/), [Hono](https://developer.watchtower15.com/sdks/node/hono/), [Next.js](https://developer.watchtower15.com/sdks/node/nextjs/); for serverless see [Serverless](https://developer.watchtower15.com/sdks/node/serverless/).

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

```ts
import { WatchTower15 } from '@watchtower15/sdk';

const wt15 = WatchTower15.fromEnvironment({ appInfo: 'billing/2.4.1' });
const me = await wt15.me();
for await (const server of wt15.servers.list({ limit: 100 })) {
  console.log(server.name, server.health_status);
}
```

## The three credentials

| Credential | Variable | Used for | Created |
| --- | --- | --- | --- |
| API key (`wt15ak_…`) | `WT15_API_KEY` | the REST API | in the console, under your account’s API keys |
| Metric source token (`wt15ms_…`) | `WT15_METRICS_TOKEN` | custom metrics | when you [create a metric source](https://docs.watchtower15.com/metrics/sources/) |
| Log source token (`wt15ls_…`) | `WT15_LOGS_TOKEN` | logs | when you [create a log source](https://docs.watchtower15.com/logs/custom-sources/) |

The SDK checks each credential’s shape locally and refuses one in the wrong slot, naming what it is. On a host that runs the WatchTower15 agent, tailing the log file with the agent is the better log path: the agent reads the file with no code in your application.

## Support

-   **Node.js.** Every Node.js LTS line from 22.12 is supported until its own end of life. Dropping one is a minor release, announced in the release before it.
-   **TypeScript.** 5.0 and later, under `nodenext`, `bundler` and (for a `"module": "commonjs"` project before TypeScript 6) `node10` resolution; ES modules and CommonJS are both published. The declarations name `fetch`, `Response`, `Headers` and `AbortSignal`, so a project needs `@types/node` or the DOM lib.
-   **Frameworks.** NestJS 11 and 12; pino 9 and 10; winston 3; Express 5, Fastify 5, Hono 4 and Next.js 16 as recipes.
-   **Versions.** Semantic Versioning, independent of the API’s `v1`: a new API operation is a minor release, a change that breaks the SDK’s own signatures or types a major one, and a generated type’s name never changes. All four packages are released together.
-   **Tested.** The core on Node 22.12.0 and 26; each integration on 22.12.0 and 26, at its lowest and newest supported framework or logger line; the recipes on Node 24.
-   **Other runtimes.** Bun, Deno and Cloudflare Workers are expected to work (the core uses `fetch` and Web Crypto) and are not tested. Browsers are refused unless `dangerouslyAllowBrowser` is set.
-   **Security fixes** ship in the newest minor as a patch release at once.

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