Registry / web-framework / compression-with-brotli

compression-with-brotli

JSON →
library1.7.5jsnpmunverified

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-brotli
INSTALL
IMPORT
SIG · COMPRESSION-WITH-B
C
compression-with-brotli
web-frameworkjavascriptv1.7.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const compression = require('compression')
import compression from 'compression'
CommonJS only; no ESM wrapper. Use require().
default
import compression from 'compression'
import { compression } from 'compression'
Default export, not named. For ESM environments, use the default import.
compression
const compression = require('compression')
const { compression } = require('compression')
The package exports a single function directly, not an object.

Basic Express server with compression middleware. Handles a 100KB string response that will be compressed.

const express = require('express'); const compression = require('compression'); const app = express(); // Enable compression for all responses app.use(compression()); // Route that returns a large response app.get('/large', (req, res) => { const largeString = 'x'.repeat(1024 * 100); // 100KB string res.send(largeString); }); app.listen(3000, () => { console.log('Server running on port 3000'); });
Debug
Known issues
gotchaBrotli compression requires Node.js >= v11.7.0 or v10.16.0. Older Node versions will fall back to gzip.
fix
Upgrade Node.js to v11.7.0+ or v10.16.0+ for brotli support.
affects: >=1.0.0
deprecatedThe option 'level' with value -1 (default) is equivalent to zlib.Z_DEFAULT_COMPRESSION (level 6). Use explicit level for clarity.
fix
Set level explicitly: compression({ level: 6 }).
affects: >=1.0.0
gotchaCompression is skipped for responses with Cache-Control: no-transform. Be aware if you're using CDNs or reverse proxies.
fix
Remove no-transform directive if compression is desired.
affects: >=1.0.0
gotchaThe middleware compresses only if the request's Accept-Encoding header includes the encoding. Client must support it.
fix
Ensure client sends Accept-Encoding header.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Compression requires a valid Accept-Encoding header
Request without Accept-Encoding header
fix
Ensure the client sends Accept-Encoding header, e.g., 'gzip, deflate'.
TypeError: Cannot read property 'pipe' of undefined
Response body is not a stream or is null
fix
Make sure the response body is a stream or string/buffer.
Error: write after end
Response already sent before compression completes
fix
Ensure no early res.end() calls; use res.write() properly.
Upgrade
Version history
1.7.5latest on npm
Audit
Dependencies
acceptsrequiredNegotiates content encoding
bytesrequiredParses byte size strings
compressiblerequiredDetermines if content type is compressible
debugrequiredDebug logging
on-headersrequiredMonitors response headers
safe-bufferrequiredBuffer API polyfill
varyrequiredAdds Vary header
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
compression-with-brotli — npm install compression-with-brotli · libregistry