Quick-reference recipe card - copy-paste ready.
import express from "express" ;
import { performance, monitorEventLoopDelay } from "node:perf_hooks" ;
const loopDelay = monitorEventLoopDelay ({ resolution: 20 });
loopDelay. enable ();
const app = express ();
// Incident reproduction: 3MB JSON array sync parse
app. post ( "/webhooks/heavy" , express. raw ({ type: "application/json" , limit: "5mb" }), ( req , res ) => {
const start = performance. now ();
const payload = JSON . parse (req.body. toString ( "utf8" ));
const elapsed = performance. now () - start;
res. json ({ items: payload. length , parseMs: elapsed });
});
// Mitigation: reject oversized sync parse routes; offload to queue
app. post ( "/webhooks/queued" , express. raw ({ type: "application/json" , limit: "256kb" }), ( req , res ) => {
if (req.body. length > 256 * 1024 ) {
return res. status ( 413 ). json ({ error: { code: "PAYLOAD_TOO_LARGE" } });
}
const payload = JSON . parse (req.body. toString ( "utf8" ));
res. status ( 202 ). json ({ accepted: true , items: payload. length });
});
app. get ( "/health" , ( _req , res ) => {
const p99 = loopDelay. percentile ( 99 ) / 1e6 ; // ms
if (p99 > 100 ) return res. status ( 503 ). json ({ ok: false , eventLoopLagP99Ms: p99 });
res. json ({ ok: true , eventLoopLagP99Ms: p99 });
});
app. listen ( 3000 );
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+ , TypeScript 5.6+ , Express 5 , Fastify 5 , and NestJS 11 .