resp-modifier is a Node.js middleware designed for Connect and Express applications, enabling the modification of HTTP response bodies, particularly HTML. It generalizes the functionality found in packages like `connect-livereload`, focusing solely on response modification rather than live reload specifics. The package allows developers to define multiple replacement rules to transform the outgoing response content, making it suitable for tasks such as injecting scripts, modifying links, or censoring content dynamically. The current stable version is 6.0.2. While the release cadence is not explicitly defined, regular updates suggest active maintenance. Key differentiators include its focused scope on response manipulation and compatibility with standard Connect-style middleware architectures.
npm install resp-modifierVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up `resp-modifier` as Express middleware to perform string replacements and inject content into HTML responses.
Ensure `app.use(respModifier(...))` is called early in your middleware chain, before route handlers that `res.send()` or `res.json()`.
Be mindful of performance implications for large response bodies. Consider adding checks within your modification logic to only modify responses of specific content types or sizes if performance is critical.
Utilize the middleware's configuration to specify content types to target or include logic to bypass modification for certain `res.getHeader('Content-Type')` values. For example, some libraries allow a `filter` function to control when modification applies.Review the order of your Express middleware. Ensure `resp-modifier` is positioned before any route handlers that call `res.send()` or `res.json()`, and before other middleware that might finalize the response stream.
Verify that `resp-modifier` is correctly configured for your content's encoding (e.g., UTF-8). Check if there are any options to manage `Content-Length` header auto-correction. If modifications are drastic, consider debugging the middleware's internal buffer handling.
No dependency data recorded yet.