{"library":"resp-modifier","title":"Connect/Express Response Modifier Middleware","description":"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install resp-modifier"],"cli":null},"imports":["import respModifier from 'resp-modifier';","const respModifierCJS = require('resp-modifier');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import express from 'express';\nimport respModifier from 'resp-modifier';\n\nconst app = express();\nconst PORT = process.env.PORT || 3000;\n\n// Basic usage: replace 'world' with 'developer' in HTML responses\napp.use(respModifier({\n  rules: [\n    {\n      match: /world/g,\n      replace: 'developer'\n    },\n    {\n      match: /<\\/body>/,\n      replace: '<script>console.log(\"Response modified!\")</script></body>'\n    }\n  ]\n}));\n\napp.get('/', (req, res) => {\n  res.status(200).send('<h1>Hello, world!</h1><p>This is a test page.</p>');\n});\n\napp.get('/json', (req, res) => {\n  // resp-modifier typically targets HTML responses, \n  // JSON responses might not be affected or could be corrupted if not handled carefully.\n  res.json({ message: 'Hello, JSON world!' });\n});\n\napp.listen(PORT, () => {\n  console.log(`Server listening on http://localhost:${PORT}`);\n  console.log('Try visiting / and /json');\n});","lang":"javascript","description":"Demonstrates setting up `resp-modifier` as Express middleware to perform string replacements and inject content into HTML responses.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}