A comprehensive, production-ready toolkit for building observable and reliable Node.js applications and APIs.
Do you ever find yourself in these scenarios?
- "My application is breaking and I don't know why."
- "It is taking me way too long to resolve incidents. How do I improve MTTR (Mean Time to Resolve)?"
- "I want to be more proactive and address issues before a customer reports them."
- "I need to know the usage patterns of my application so that I can prioritize work for maximum ROI."
- "We shipped a fix but still cannot prove in production that latency or errors actually improved."
- "Two services disagree on what happened for the same request, and we have no shared request id or trace to reconcile them."
- "Our logs are a wall of text; finding one user's session or one bad deploy takes forever."
Observability is how you answer those questions with evidence instead of guesses. Better Application Toolkit helps in two ways:
- Documentation that captures recommendations and patterns you can adopt deliberately
- Libraries you can wire into your app so those practices are easier to ship and keep consistent.
Better Application Toolkit (BAT) is a suite of TypeScript packages designed to improve observability, reliability, and developer experience for Node.js web applications. All packages are designed to work in both Node.js and browser environments (where applicable).
- Observability recommendations — MELT framing, logging practices, and how traces and metrics fit alongside BAT.
- Understanding AsyncLocalStorage — how ALS works, use cases, pitfalls, and how BAT uses it for logging.
- Package specifics: @batkit/logger, @batkit/express-middleware, and the AsyncLocalStorage guide above.
- @batkit/rfc9457 - Zod schemas and types for RFC 9457 (Problem Details for HTTP APIs)
- @batkit/errors - Standardized error classes with structured troubleshooting information
- @batkit/logger - Logger facade with default console implementation
- @batkit/logger-pino - Pino.js implementation of the logger facade (works in browser and Node.js)
- @batkit/express-middleware - Express.js middleware for error handling and request context (Node.js only)
- Express API — production-ready Express.js app demonstrating all BAT packages
- CLI app — minimal terminal demo of the logger stack (
vp run clifrom the repo root)
- ✨ Universal Design - Most packages work in both Node.js and browser environments
- 🎯 Type-Safe - Full TypeScript support with exported types
- 📦 Dual Module Format - ESM and CommonJS builds for maximum compatibility
- 🧪 Well Tested - Comprehensive test coverage with Vitest
- 📚 Standards-Based - Implements RFC 9457 for standardized error responses
- 🔍 Observable - Built-in structured logging and request context tracking
- ⚡ Modern -
@batkit/logger's optional/async-localentry uses AsyncLocalStorage for request-scoped context (Node.js only)
Install the packages you need (npm, pnpm, yarn, or in a Vite+ project, vp add):
pnpm add @batkit/logger @batkit/errors @batkit/express-middlewareimport { LoggerFacade } from "@batkit/logger";
import { ContextualLoggerProvider } from "@batkit/logger/async-local";
import { PinoLoggerProvider } from "@batkit/logger-pino";
import { NotFoundError } from "@batkit/errors";
import { errorHandler, logContextMiddleware } from "@batkit/express-middleware";
import express from "express";
import { randomUUID } from "node:crypto";
LoggerFacade.setProvider(new ContextualLoggerProvider(new PinoLoggerProvider({ level: "info" })));
const app = express();
app.use(express.json());
app.use(
logContextMiddleware({
initialContext: (req) => ({ requestId: req.get("x-request-id") ?? randomUUID() }),
}),
);
// Your routes
app.get("/users/:id", (req, res) => {
const user = findUser(req.params.id);
if (!user) {
throw new NotFoundError("User", req.params.id);
}
res.json(user);
});
// Add error handler (must be last)
app.use(errorHandler());
app.listen(3000);See ROADMAP.md.
We welcome contributions. See CONTRIBUTING.md for local development with Vite+ (vp), workspace layout, common commands, and adding a changeset when you change packages.
MIT © Ken Courville
- Vite+ — unified
vptoolchain (install, run, check, test, pack) - RFC 9457 - Problem Details for HTTP APIs — the HTTP problem-details standard
@batkit/rfc9457schemas implement - Express.js Documentation — the web framework
@batkit/express-middlewaretargets - Pino Logger — high-performance JSON logger backing
@batkit/logger-pino - Changesets — versioning/changelog tool driving
pnpm changesetand releases - knip — unused files/deps/exports check (
pnpm knip) - publint — package.json/exports validation (
pnpm publint) - Are the Types Wrong? — dual ESM/CJS type resolution check (
pnpm attw)