node-http-proxy-json is a specialized library, currently at version 0.1.9, designed to intercept and transform JSON responses from a proxied server when used in conjunction with node-http-proxy. Its primary function is to allow developers to modify JSON payloads on the fly, making it suitable for scenarios like API mocking, data manipulation, or stripping sensitive information before the response reaches the client. The library handles responses compressed with `gzip` or `deflate`, as well as uncompressed data. Unlike general-purpose stream manipulation tools such as Harmon, which targets HTML/XML, node-http-proxy-json focuses exclusively on JSON. Given its last commit in 2016, the project appears to be abandoned, with no active development or maintenance, and no clear release cadence, making it potentially unsuitable for new projects requiring ongoing support or modern features.
npm install node-http-proxy-jsonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a proxy server using `node-http-proxy` and `node-http-proxy-json` to intercept and modify gzipped JSON responses from a target server. It modifies the 'age' field and removes the 'version' field before sending the response to the client.
Evaluate modern alternatives for proxying and response modification (e.g., 'http-proxy-middleware' with custom body parsers, or writing custom stream handlers) if long-term maintenance and security are critical.
Ensure your target server only uses supported compression formats or implement custom handling for unsupported formats by extending `http-proxy`'s `proxyRes` event handler manually.
Always check `body` for null/undefined inside your callback function. Consider verifying `Content-Type` header before calling `modifyResponse` if unexpected data types are possible from the target.
Add a check `if (body) { ... }` before attempting to access properties of the `body` object. Verify the `Content-Type` header and `Content-Encoding` from the `proxyRes` object to ensure it's JSON and uses a supported compression.Configure the target server to use 'gzip', 'deflate', or no compression. Alternatively, consider using a different proxy library or implementing a custom `proxyRes` handler to decompress Brotli manually before processing the JSON.