{"id":18555,"library":"micro-compress","title":"micro-compress","description":"Middleware to add gzip/brotli compression to HTTP microservices built with the Micro framework (from ZEIT/Now). Version 1.0.0 is stable and wraps the popular compression npm package, passing all options through. It is designed specifically for Micro's async request handler pattern, not Express or other frameworks. The package is minimal (no dependencies beyond compression and micro) and follows the same promise-based flow as Micro itself. It is released under MIT license and has not seen updates since 2017, indicating maintenance status.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/joakimbeng/micro-compress","tags":["javascript","micro","compression","gzip","microservice","http","compress"],"install":[{"cmd":"npm install micro-compress","lang":"bash","label":"npm"},{"cmd":"yarn add micro-compress","lang":"bash","label":"yarn"},{"cmd":"pnpm add micro-compress","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core compression logic (gzip, deflate, brotli).","package":"compression","optional":false},{"reason":"Peer dependency for HTTP microservice framework.","package":"micro","optional":false}],"imports":[{"note":"CommonJS only; no ESM exports. Default export is the compress function.","wrong":"import compress from 'micro-compress';","symbol":"default","correct":"const compress = require('micro-compress');"},{"note":"Named export 'compress' does not exist. Use default export directly.","wrong":"const { compress } = require('micro-compress');","symbol":"compress (with options)","correct":"const compress = require('micro-compress');\nmodule.exports = compress({ level: 9 }, handler);"},{"note":"For TypeScript, use import equals (require style) or // @ts-ignore. No type declarations.","wrong":"import compress from 'micro-compress';","symbol":"TypeScript usage","correct":"import compress = require('micro-compress');"}],"quickstart":{"code":"const { send, json } = require('micro');\nconst compress = require('micro-compress');\nconst handler = async (req, res) => {\n  const body = await json(req);\n  send(res, 200, body);\n};\nmodule.exports = compress(handler);","lang":"javascript","description":"Wraps a Micro request handler with compression middleware. The handler remains async, and the response is gzip-compressed if accepted."},"warnings":[{"fix":"Use compression middleware designed for your framework (e.g., compression for Express).","message":"micro-compress only works with the Micro framework, not Express or other HTTP servers.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use require('micro-compress') instead of import. If you need ESM, transpile or use dynamic import.","message":"No ESM support; must use CommonJS require().","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass options as first argument: compress({level: 9}, handler). Do not pass handler as first argument.","message":"Options object is the first argument; if omitted, default compression options are used.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If brotli needed, ensure compression@>=1.7.0 is installed and pass { brotli: { enabled: true } }. Check compression docs.","message":"micro-compress does not support brotli compression natively; relies on compression package which may not include brotli in older versions.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install micro-compress in the project root.","cause":"Forgot to run npm install or installed in wrong directory.","error":"Error: Cannot find module 'micro-compress'"},{"fix":"Use const compress = require('micro-compress');","cause":"Using named import { compress } instead of default require.","error":"TypeError: compress is not a function"},{"fix":"Ensure micro is installed: npm install micro. Then wrap: compress(handler) or compress(options, handler).","cause":"Passed handler as first argument without wrapping correctly or missing micro peer dependency.","error":"TypeError: Cannot read property 'writeHead' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}