Registry / web-framework / express-uglify-middleware

express-uglify-middleware

JSON →
library1.0.2jsnpmunverified

This package provides an Express middleware designed to dynamically minify JavaScript files using UglifyJS upon request. As of its last known stable release (version 1.0.2), it targets very old Node.js environments (compatible with Node.js >= 0.8.0) and likely older versions of Express and UglifyJS. It enables on-the-fly minification, which was a common pattern in older web applications, but is now largely superseded by build-time asset compilation and minification using tools like Webpack or Vite. The package appears to be abandoned, with no active development or maintenance since its initial release, making it unsuitable for modern JavaScript projects or production use. Its main differentiator was in-request minification, contrasting with modern build-step approaches.

npm install express-uglify-middleware
INSTALL
IMPORT
SIG · EXPRESS-UGLIFY-MID
E
express-uglify-middleware
web-frameworkjavascriptv1.0.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

uglifyMiddleware
✓ const uglifyMiddleware = require('express-uglify-middleware');
✗ import uglifyMiddleware from 'express-uglify-middleware';
This package exclusively uses CommonJS `require()` syntax due to its age and does not support ES Modules `import` syntax.

This quickstart sets up a basic Express application that uses `express-uglify-middleware` to dynamically minify a source JavaScript file into a public directory, serving it via a '/js' prefix. It demonstrates the configuration options and a simple Express server setup.

const express = require('express'); const path = require('path'); const uglifyMiddleware = require('express-uglify-middleware'); const app = express(); const port = 3000; // Define paths for source JavaScript and public destination const javascriptSourceDir = path.join(__dirname, 'javascript_src'); const publicJsDestDir = path.join(__dirname, 'public', 'js'); // Create dummy source directory and file for demonstration require('fs').mkdirSync(javascriptSourceDir, { recursive: true }); require('fs').writeFileSync(path.join(javascriptSourceDir, 'app.js'), 'function hello(name) { console.log("Hello, " + name); } hello("World");'); // Configure and use the uglifyMiddleware app.use(uglifyMiddleware({ src: javascriptSourceDir, dest: publicJsDestDir, prefix: '/js', compressFilter: /\.js$/, compress: true, force: true, // Forces re-compression on every request (for testing) debug: true })); // Serve static files from the 'public' directory (e.g., the minified JS) app.use('/public', express.static(path.join(__dirname, 'public'))); // Basic route to demonstrate app.get('/', (req, res) => { res.send('<h1>Express Uglify Middleware Demo</h1><p>Visit <a href="/js/app.js">/js/app.js</a> to see minified output.</p><p>Check the console for debug messages if `debug: true`.</p>'); }); app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); console.log(`Source JS: ${javascriptSourceDir}`); console.log(`Minified JS (expected): ${path.join(publicJsDestDir, 'app.js')}`); console.log('You might need to clear browser cache for changes to appear if `force: false`.'); });
Debug
Known issues
breakingThis package is designed for Node.js environments `>= 0.8.0` and is incompatible with modern Node.js versions (e.g., Node.js 12+). Running it on recent Node.js versions will likely result in runtime errors due to API changes and deprecated modules.
fix
Do not use this package in modern Node.js environments. For current projects, utilize build tools like Webpack or Vite with Terser for JavaScript minification.
affects: >=1.0.0
breakingThe package likely uses an extremely old version of UglifyJS, which does not support modern JavaScript syntax (ES2015+). Attempting to minify ES6+ code will result in `SyntaxError`s or incorrect minification.
fix
Avoid using this middleware for modern JavaScript. Modern projects should use build tools with up-to-date minifiers like Terser that support the latest ECMAScript features.
affects: >=1.0.0
breakingThis middleware was built for older Express versions (likely 3.x or 4.x). While basic `app.use` might still function, deep incompatibilities with Express 5.x or newer middleware patterns are highly probable, leading to unexpected behavior or errors.
fix
This package is not compatible with modern Express applications. Consider a different approach for asset management that integrates with current Express practices.
affects: >=1.0.0
deprecatedThe pattern of dynamic, on-the-fly minification in a production environment is generally considered an anti-pattern. It adds latency to requests, consumes server resources for each un-cached request, and complicates caching strategies. Modern best practices involve pre-building and minifying assets at deploy time.
fix
Adopt a build-time asset compilation workflow (e.g., Webpack, Rollup, Vite) to minify JavaScript before deployment. Serve pre-minified assets as static files, potentially via a CDN, for optimal performance and scalability.
affects: >=1.0.0
gotchaThe `force: true` option (as shown in the example) will re-minify files on every request, which is highly inefficient and detrimental to performance in production. While useful for development, it must be set to `false` or removed for production deployments.
fix
Ensure `force: false` (or omit it for the default `false`) in production environments to enable caching of minified files and avoid redundant processing.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'uglify-js'
The `uglify-js` package, a peer dependency, was not installed or is inaccessible.
fix
Ensure `uglify-js` is installed locally: `npm install uglify-js`.
SyntaxError: Unexpected token: keyword 'const'
The version of UglifyJS used by this middleware does not support ES6 (ECMAScript 2015) or newer syntax.
fix
This package cannot minify modern JavaScript. You must either transpile your code to ES5 before passing it to this middleware or, preferably, migrate to a modern build pipeline with an up-to-date minifier like Terser.
TypeError: app.use is not a function
This error typically indicates an issue with how Express is being initialized or an incompatibility with an extremely old (pre-2.x) or corrupted Express installation.
fix
Verify that `express` is correctly installed and imported, and that you are working with an Express `Application` instance. However, this package is fundamentally incompatible with modern Express versions.
ReferenceError: require is not defined (in browser)
This package is a Node.js server-side middleware and cannot be run directly in a browser environment.
fix
This middleware is for server-side processing with Express. It generates static assets that are then served to the browser. Do not attempt to bundle or run `express-uglify-middleware` client-side.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
expressrequiredRuntime dependency for Express applications, specifically for `app.use` integration.
uglify-jsrequiredCore library responsible for JavaScript minification.
Agent activity
9 hits · last 30 days
node
8
Resources
express-uglify-middleware — npm install express-uglify-middleware · libregistry