'use strict'; const SLOW_THRESHOLD_MS = 200; function timingMiddleware(req, res, next) { const start = Date.now(); res.on('finish', () => { const duration = Date.now() - start; const msg = `${req.method} ${req.path} ${res.statusCode} ${duration}ms`; if (duration >= SLOW_THRESHOLD_MS) { console.warn(`[SLOW] ${msg}`); } else { console.log(`[timing] ${msg}`); } }); next(); } module.exports = timingMiddleware;