Express middleware that performs stream-based string replacement in HTTP response bodies on the fly. Current stable version is 1.1.0, released under MIT license, with infrequent updates. Key differentiator: works on the response stream before sending, unlike typical string replacement that buffers entire responses. Supports configurable Content-Type filtering via regex (default: text/*, application/json, application/xml). Ships TypeScript type declarations. Requires Node >=10 and Express. Not recommended for production with large or streaming responses due to potential performance overhead.
npm install string-replace-middlewareVerified import paths — ran on the pinned version, not inferred.
Sets up an Express app with string replacement middleware that replaces 'foo' with 'bar' and 'hello' with 'world' in all responses matching default content types.
Verify that your responses set an appropriate Content-Type header. Use the options.contentTypeFilterRegexp to customize matching.
Avoid using this middleware for large file downloads or streaming endpoints. Consider alternative approaches like pre-processing strings before sending.
Use targeted replacements that are unlikely to appear in code or structure. Consider adding logic to avoid replacing inside certain contexts (not provided by the library).
Use `const { stringReplace } = require('string-replace-middleware')` instead of `const stringReplace = require('string-replace-middleware')`.Run `npm install string-replace-middleware` and ensure Node.js >= 10.
Ensure you call `app.use(stringReplace({...}))` correctly. The library uses string replacement, not regex, so most special characters are safe. Check for proper Express setup.