Istanbul Middleware for TypeScript
raw JSON →istanbul-middleware-ts is a TypeScript-first middleware designed for integrating Istanbul code coverage reporting into Node.js applications, primarily with Express.js. It provides HTTP endpoints to collect, reset, merge, report, and download code coverage data. The package is currently at version 1.1.4, indicating active maintenance with several recent minor releases, and offers complete TypeScript support with type definitions. Its release cadence appears to be driven by feature additions and bug fixes within the 1.x series. A key differentiator is its modern TypeScript implementation that is compatible with the API of the original `istanbul-middleware`, making it a drop-in replacement for users seeking enhanced type safety and up-to-date Node.js practices. It offers robust functionality for CI/CD pipelines and local development environments by enabling dynamic coverage data management, HTML report generation, and LCOV/ZIP package downloads, alongside features like differential coverage reporting against git targets.
Common errors
error Cannot find module 'express' or its corresponding type declarations. ↓
npm install express @types/express error TypeError: app.use is not a function ↓
app is an instance of express() before calling app.use(). error ReferenceError: require is not defined in ES module scope ↓
import { createHandler } from 'istanbul-middleware-ts'; Warnings
gotcha The `/reset` endpoint accessible via GET requests is disabled by default for security reasons and to prevent accidental data loss. It must be explicitly enabled. ↓
gotcha Differential coverage functionality (GET /diff, GET /diff/info) requires the Python `diff-cover` package to be installed globally or available in the system's PATH, and the `diffTarget` option to be configured. ↓
Install
npm install istanbul-middleware-ts yarn add istanbul-middleware-ts pnpm add istanbul-middleware-ts Imports
- createHandler wrong
const { createHandler } = require('istanbul-middleware-ts');correctimport { createHandler } from 'istanbul-middleware-ts'; - getCoverageObject wrong
const { getCoverageObject } = require('istanbul-middleware-ts');correctimport { getCoverageObject } from 'istanbul-middleware-ts'; - resetCoverage wrong
const { resetCoverage } = require('istanbul-middleware-ts');correctimport { resetCoverage } from 'istanbul-middleware-ts';
Quickstart
import express from "express";
import { createHandler } from "istanbul-middleware-ts";
const app = express();
// Add Istanbul middleware
app.use(
"/coverage",
createHandler({
resetOnGet: true // Allow GET requests to reset coverage
})
);
app.listen(3000, () => {
console.log("Server running on http://localhost:3000");
console.log("Coverage available at http://localhost:3000/coverage");
});