Registry / devops / express-html-minify

express-html-minify

JSON →
library1.0.4jsnpmunverified

An Express.js middleware that automatically minifies HTML responses using html-minifier. This package intercepts HTML responses and reduces file size by removing whitespace, comments, and other unnecessary characters. Version 1.0.4 is the latest stable release. It has low release cadence and minimal dependencies, but its approach (intercepting res.end) can conflict with other middleware or streaming responses. Unlike other minifiers, it does not require manual wrapping of res.send or res.render.

npm install express-html-minify
INSTALL
IMPORT
SIG · EXPRESS-HTML-MINIF
E
express-html-minify
devopsjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default
const minify = require('express-html-minify');
import minify from 'express-html-minify';
This package only supports CommonJS require. ESM imports may fail.
middleware
app.use(require('express-html-minify'));
app.use(minify());
The exported value is the middleware function itself, not a factory. Do not call it.
minifyHTML
No named export exists. Only default middleware is exported.
import { minifyHTML } from 'express-html-minify';
There is no named export. The package only exposes the middleware function as default.

Shows basic Express setup with HTML minification middleware. The middleware minifies all HTML responses.

const express = require('express'); const minify = require('express-html-minify'); const app = express(); app.use(minify); app.get('/', (req, res) => { res.send('<html> <head><title>Test</title></head> <body><h1>Hello</h1></body></html>'); }); app.listen(3000);
Debug
Known issues
gotchaThe middleware intercepts res.end and may not work correctly with streaming or compressed responses.
fix
Ensure no other middleware modifies res.end before this middleware. Disable compression for HTML responses if issues occur.
affects: *
gotchaDoes not minify responses sent via res.sendFile or other methods that bypass res.send.
affects: *
deprecatedNo updates since 2017. The underlying html-minifier may have newer versions with different behavior.
fix
Consider using a more actively maintained alternative like 'compression' middleware or custom minification.
affects: <=1.0.4
Errors
Common errors & fixes
Cannot find module 'express-html-minify'
Package not installed or typo in require path.
fix
Run 'npm install express-html-minify' to install the package.
minify is not a function
The exported value is a function, but calling it as middleware factory (minify()) returns undefined.
fix
Use 'app.use(minify)' without parentheses.
TypeError: Cannot read property 'end' of undefined
Another middleware has already consumed the response or res.end is not available.
fix
Ensure the minify middleware is placed before any middleware that may modify res.end.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
html-minifierrequiredCore minification engine used to process HTML content.
Agent activity
2 hits · last 30 days
node
2
Resources
express-html-minify — npm install express-html-minify · libregistry