npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alikhan-devs/watchtower-sdk

v1.0.1

Published

Lightweight monitoring SDK for Express apps — automatically tracks response times, error rates, and sends metrics to WatchTower.

Downloads

38

Readme

@alikhan-devs/watchtower-sdk

Lightweight Express monitoring middleware for WatchTower.

Drop it into your app and it will automatically:

  • Track response time for every request
  • Capture status codes and error-rate data
  • Normalize route patterns like /users/123 to /users/:id
  • Batch metrics and send them to your WatchTower API
  • Flush in the background without keeping your Node process alive

Installation

npm install @alikhan-devs/watchtower-sdk

This package has a peer dependency on Express:

npm install express

Requirements

  • Node.js 18+ recommended
  • Express 4.18+ or 5+
  • A WatchTower app apiKey from your dashboard
  • Your WatchTower API base URL

Quick Start

CommonJS

const express = require('express');
const { watchTower } = require('@alikhan-devs/watchtower-sdk');

const app = express();

app.use(watchTower({
  apiKey: 'your-app-api-key',
  host: 'http://localhost:3000'
}));

app.get('/users/:id', (req, res) => {
  res.json({ id: req.params.id });
});

app.listen(4000);

ESM / TypeScript

import express from 'express';
import { watchTower } from '@alikhan-devs/watchtower-sdk';

const app = express();

app.use(watchTower({
  apiKey: 'your-app-api-key',
  host: 'http://localhost:3000'
}));

app.get('/health', (_req, res) => {
  res.send('ok');
});

app.listen(4000);

How It Works

The middleware listens for each response finish event, records:

  • route
  • method
  • statusCode
  • responseTime
  • timestamp

It then batches those metrics and sends them to:

POST /api/ingest

with:

x-api-key: <your-app-api-key>

API

watchTower(options)

Creates the Express middleware and starts the background flusher.

import { watchTower } from '@alikhan-devs/watchtower-sdk';

const middleware = watchTower({
  apiKey: 'your-app-api-key',
  host: 'http://localhost:3000',
  flushIntervalMs: 10000,
  maxBatchSize: 100,
  debug: false
});

Options

| Option | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | apiKey | string | Yes | - | App API key from WatchTower dashboard | | host | string | No | http://localhost:3000 | Base URL of your WatchTower API | | flushIntervalMs | number | No | 10000 | Flush queued metrics every N milliseconds | | maxBatchSize | number | No | 100 | Flush immediately once queue reaches this size | | debug | boolean | No | false | Log SDK flush activity to console |

Graceful Shutdown

The returned middleware includes a .stop() method so you can flush remaining metrics before process exit.

import express from 'express';
import { watchTower } from '@alikhan-devs/watchtower-sdk';

const app = express();
const monitoring = watchTower({
  apiKey: 'your-app-api-key',
  host: 'http://localhost:3000'
});

app.use(monitoring);

process.on('SIGTERM', async () => {
  await monitoring.stop?.();
  process.exit(0);
});

What Gets Ignored

The middleware skips:

  • /health
  • /favicon

Route Normalization

If Express provides the matched route, the SDK uses it directly.

Examples:

  • /users/123 -> /users/:id
  • /orders/550e8400-e29b-41d4-a716-446655440000 -> /orders/:id
  • Long cuid-style IDs are also normalized to :id

This keeps your dashboard clean and prevents route-cardinality explosions.

Advanced Exports

If you need more control, the package also exports:

import { WatchTowerClient, createMiddleware } from '@alikhan-devs/watchtower-sdk';

Dependencies

Runtime dependencies

This package currently has no direct runtime dependencies.

Peer dependencies

  • express: ^4.18.0 || ^5.0.0

That means users should install express in their own app:

npm install express

Troubleshooting

No metrics appearing

  • Make sure host points to your WatchTower API, not the dashboard URL
  • Make sure apiKey is the app API key from WatchTower
  • Enable debug: true to inspect flush behavior
  • Confirm your WatchTower API is reachable from the monitored app

Using Node below 18

This SDK relies on fetch. If you are on an older Node version, upgrade Node or provide a compatible fetch polyfill in your environment.

License

MIT