Registry / devops / shiny-express-formatter

shiny-express-formatter

JSON →
library1.0.0jsnpmunverified

Middleware for Express.js that formats HTTP request and response objects (including optional body capture) for logging. Version 1.0.0, single release. Differentiates from other logging middleware by providing separate callbacks for request and response capture, allowing fine-grained control over header/body logging via boolean or function options. Non-streaming response body capture only. Designed for Node.js Express apps.

npm install shiny-express-formatter
INSTALL
IMPORT
SIG · SHINY-EXPRESS-FORM
S
shiny-express-formatter
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const requestFormatter = require('shiny-express-formatter');
import requestFormatter from 'shiny-express-formatter';
Package is CJS-only, no ESM export. Use require().
formatRequests
app.use(requestFormatter.formatRequests(options));
app.use(requestFormatter.formatRequests(options));
formatRequests is a function that returns middleware; call it with options.
formatResponse
app.use(requestFormatter.formatResponse(options));
app.use(requestFormatter.formatResponse(options));
formatResponse is a function that returns middleware; call it with options.

Sets up Express app with request and response formatter middleware, including callbacks and body capture options.

const express = require('express'); const requestFormatter = require('shiny-express-formatter'); const app = express(); app.use(express.json()); // body parser first app.use(requestFormatter.formatRequests({ onRequestCaptured: (reqLog) => console.log('Request:', reqLog), captureRequestBody: true, logRequestHeaders: (req) => { const { authorization, ...rest } = req.headers; return rest; } })); app.use(requestFormatter.formatResponse({ onResponseCaptured: (reqLog, resLog) => console.log('Response:', resLog), captureResponseBody: (req, res) => res.statusCode === 200, logResponseHeaders: true })); app.get('/api', (req, res) => res.json({ message: 'ok' })); app.listen(3000);
Debug
Known issues
gotchaBody parser middleware (e.g., express.json()) must be added BEFORE requestFormatter middleware to capture request bodies.
fix
Ensure app.use(express.json()) is called before requestFormatter.formatRequests().
affects: >=1.0.0
gotchaResponse body capture only works for non-streaming responses (e.g., res.json, res.send). Streaming bodies (e.g., res.pipe) are not captured.
fix
Use for non-streaming endpoints only.
affects: >=1.0.0
gotchaIf onRequestCaptured or onResponseCaptured callbacks throw, the error may crash the server unless caught.
fix
Wrap callbacks in try-catch or ensure they are error-tolerant.
affects: >=1.0.0
gotchacaptureRequestBody and captureResponseBody default to false; body will be empty unless explicitly enabled.
fix
Set captureRequestBody: true or provide a filter function.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read property 'id' of undefined
onRequestCaptured callback not invoked if middleware order is wrong or route not hit.
fix
Ensure requestFormatter.formatRequests() is added before your routes.
TypeError: requestFormatter.formatRequests is not a function
Incorrect import; trying to import as ES module or using named import incorrectly.
fix
Use const requestFormatter = require('shiny-express-formatter'); then call requestFormatter.formatRequests().
Response body is empty even with captureResponseBody: true
Response body capture only works if the response is not streamed (e.g., res.sendFile).
fix
Only expect body for non-streaming responses.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
expressoptionalPeer dependency for middleware integration
Agent activity
4 hits · last 30 days
node
4
Resources
shiny-express-formatter — npm install shiny-express-formatter · libregistry