Node.js compression middleware for Express/Connect that supports gzip, deflate, and brotli response compression. Current stable version is 1.8.1, released March 2025, with a moderate release cadence. Key differentiators: built-in brotli support (requires Node >= v11.7.0 or v10.16.0), automatic filtering based on Content-Type via the compressible package, and flexible configuration of compression levels and memory usage. It is part of the Express.js ecosystem and is widely used with Express and plain Node HTTP servers.
npm install compression-with-brotliVerified import paths — ran on the pinned version, not inferred.
Basic Express server with compression middleware. Handles a 100KB string response that will be compressed.
Upgrade Node.js to v11.7.0+ or v10.16.0+ for brotli support.
Set level explicitly: compression({ level: 6 }).Remove no-transform directive if compression is desired.
Ensure client sends Accept-Encoding header.
Ensure the client sends Accept-Encoding header, e.g., 'gzip, deflate'.
Make sure the response body is a stream or string/buffer.
Ensure no early res.end() calls; use res.write() properly.