compress
raw JSON → 0.99.0 verified Sat Apr 25 auth: no javascript
Compress is a Node.js middleware for HTTP message compression, supporting gzip, deflate, and brotli encodings. The current stable version is 0.99.0, with infrequent releases. It differs from alternatives like compression by focusing on simplicity and low overhead, but is less actively maintained. Suitable for compressing HTTP responses in Express/Connect apps.
Common errors
error TypeError: compress is not a function ↓
cause Incorrect default import in CommonJS environment.
fix
Use
const compress = require('compress').default; Warnings
deprecated compress 0.x is not actively maintained; consider alternatives like compression. ↓
fix Migrate to the 'compression' npm package for better maintenance.
gotcha The compress function expects an HTTP response with a writable stream; fails if used improperly. ↓
fix Ensure the response object has writable stream methods (e.g., from http.createServer).
Install
npm install compress yarn add compress pnpm add compress Imports
- compress wrong
const compress = require('compress')correctimport compress from 'compress' - compress wrong
const compress = require('compress')correctconst compress = require('compress').default - compressObj wrong
const { compress } = require('compress')correctimport { compressObj } from 'compress'
Quickstart
import compress from 'compress';
import http from 'http';
const server = http.createServer((req, res) => {
compress(req, res, () => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
});
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});