Express middleware that enhances the response object with a `formatter` property providing readable methods like `ok()`, `created()`, `badRequest()`, etc. Responses are automatically structured: success (2xx/3xx) returns `{ data: ... }`, client/server errors (4xx/5xx) return `{ error: ... }`, and an optional second parameter adds a `meta` field. Version 2.0.2 (latest) ships with TypeScript declarations. It follows a simple, opinionated format and is intended for projects wanting consistent JSON API responses without heavy frameworks. Release cadence is intermittent; maintained as of 2023.
npm install express-response-formatterNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates attaching the middleware and using the ok() and badRequest() formatter methods with metadata.
Ensure app.use(responseEnhancer()) not app.use(responseEnhancer).
Always pass the data/errors argument, even if empty array.
Avoid using 'data' or 'error' keys in meta object; they are reserved.
If you need other formats, use a separate middleware before this one.
Add app.use(responseEnhancer()) before route definitions.
Call responseEnhancer(): app.use(responseEnhancer()).
Import types: import { ResponseFormatter } from 'express-response-formatter' and extend Response interface.Ensure meta object does not contain reserved keys 'data' or 'error'.