Registry / web-framework / lws-compress

lws-compress

JSON →
library3.1.0jsnpmunverified

Response compression middleware for the lws (local-web-server) framework, enabling gzip compression for HTTP responses. Current stable version is 3.1.0, compatible with Node.js >=12.17. It adds --compress and --compress.threshold CLI options to lws, with a default compression threshold of 1024 bytes. Published under the lwsjs organization, this middleware is a lightweight, focused solution for local development servers, following the standard.js code style.

npm install lws-compress
INSTALL
IMPORT
SIG · LWS-COMPRESS
L
lws-compress
web-frameworkjavascriptv3.1.0
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.

compress
import compress from 'lws-compress'
import { compress } from 'lws-compress'
Default export since v3.
compress
const compress = require('lws-compress')
const { compress } = require('lws-compress')
CommonJS: default export, not named.
CompressMiddleware
import CompressMiddleware from 'lws-compress'
Alias for the default export; no named export exists.

Starts an lws server with response compression middleware, setting a custom compression threshold of 2048 bytes.

import lws from 'lws' import compress from 'lws-compress' const server = lws({ port: 8080, stack: [compress], compress: { threshold: 2048 } }) console.log('Server running on http://localhost:8080')
lws --version
Debug
Known issues
breakingv3 changed from CommonJS to ESM-only. This breaks require() calls in Node.js versions <12.17 or projects not using ESM.
fix
Use ESM imports (import compress from 'lws-compress') or upgrade to Node.js >=12.17 and set type: 'module' in package.json. For CJS, use dynamic import: const compress = (await import('lws-compress')).default.
affects: >=3.0.0
breakingv3 removed the named export 'compress'. Previously both default and named exports were available.
fix
Use default import only: import compress from 'lws-compress'.
affects: >=3.0.0
gotchaCompression threshold is in bytes, not kilobytes. Setting threshold to 1 applies compression to responses >=1 byte, effectively always compressing.
fix
Ensure threshold is specified in bytes (e.g., 1024 for 1KB).
affects: >=1.0.0
gotchaThe --compress option must be explicitly passed to enable compression. Without it, no compression occurs even if the middleware is in the stack.
fix
Use --compress (or -z) when launching lws, or pass compress: true in lws options.
affects: >=1.0.0
gotchaCompression only applies to responses with content-type that are compressible (e.g., text/html, application/json). Binary files may be skipped.
fix
Check lws documentation for compressible content types or implement custom logic.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Named export 'compress' not found. The requested module 'lws-compress' is a CommonJS module, which may not support all module.exports as named exports.
Using named import { compress } from 'lws-compress' with ESM import syntax, but the package no longer provides that named export (since v3).
fix
Use default import: import compress from 'lws-compress'
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/lws-compress/index.js from /path/to/project/app.js not supported.
Attempting to use require() with an ESM-only package (v3+).
fix
Switch to ESM: use import or type: 'module' in package.json. Or use dynamic import: const compress = (await import('lws-compress')).default
TypeError: compress is not a function
Importing the module incorrectly, e.g., using named import when default import is required.
fix
Ensure you use default import: import compress from 'lws-compress' or const compress = require('lws-compress').default
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
lwsrequiredPeer dependency: lws-compress is a middleware for the lws framework and requires lws to function.
Agent activity
2 hits · last 30 days
node
2
Resources
lws-compress — npm install lws-compress · libregistry