{"id":17645,"library":"express-uglify-middleware","title":"Express Uglify Middleware","description":"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.","status":"abandoned","version":"1.0.2","language":"javascript","source_language":"en","source_url":"git://github.com/Elgaeb/express-uglify-middleware","tags":["javascript","uglifyjs","express","minify"],"install":[{"cmd":"npm install express-uglify-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add express-uglify-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-uglify-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for Express applications, specifically for `app.use` integration.","package":"express","optional":false},{"reason":"Core library responsible for JavaScript minification.","package":"uglify-js","optional":false}],"imports":[{"note":"This package exclusively uses CommonJS `require()` syntax due to its age and does not support ES Modules `import` syntax.","wrong":"import uglifyMiddleware from 'express-uglify-middleware';","symbol":"uglifyMiddleware","correct":"const uglifyMiddleware = require('express-uglify-middleware');"}],"quickstart":{"code":"const express = require('express');\nconst path = require('path');\nconst uglifyMiddleware = require('express-uglify-middleware');\n\nconst app = express();\nconst port = 3000;\n\n// Define paths for source JavaScript and public destination\nconst javascriptSourceDir = path.join(__dirname, 'javascript_src');\nconst publicJsDestDir = path.join(__dirname, 'public', 'js');\n\n// Create dummy source directory and file for demonstration\nrequire('fs').mkdirSync(javascriptSourceDir, { recursive: true });\nrequire('fs').writeFileSync(path.join(javascriptSourceDir, 'app.js'), 'function hello(name) { console.log(\"Hello, \" + name); } hello(\"World\");');\n\n// Configure and use the uglifyMiddleware\napp.use(uglifyMiddleware({\n  src: javascriptSourceDir,\n  dest: publicJsDestDir,\n  prefix: '/js',\n  compressFilter: /\\.js$/,\n  compress: true,\n  force: true, // Forces re-compression on every request (for testing)\n  debug: true\n}));\n\n// Serve static files from the 'public' directory (e.g., the minified JS)\napp.use('/public', express.static(path.join(__dirname, 'public')));\n\n// Basic route to demonstrate\napp.get('/', (req, res) => {\n  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>');\n});\n\napp.listen(port, () => {\n  console.log(`Server listening at http://localhost:${port}`);\n  console.log(`Source JS: ${javascriptSourceDir}`);\n  console.log(`Minified JS (expected): ${path.join(publicJsDestDir, 'app.js')}`);\n  console.log('You might need to clear browser cache for changes to appear if `force: false`.');\n});","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"This package is not compatible with modern Express applications. Consider a different approach for asset management that integrates with current Express practices.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure `force: false` (or omit it for the default `false`) in production environments to enable caching of minified files and avoid redundant processing.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `uglify-js` is installed locally: `npm install uglify-js`.","cause":"The `uglify-js` package, a peer dependency, was not installed or is inaccessible.","error":"Error: Cannot find module 'uglify-js'"},{"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.","cause":"The version of UglifyJS used by this middleware does not support ES6 (ECMAScript 2015) or newer syntax.","error":"SyntaxError: Unexpected token: keyword 'const'"},{"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.","cause":"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.","error":"TypeError: app.use is not a function"},{"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.","cause":"This package is a Node.js server-side middleware and cannot be run directly in a browser environment.","error":"ReferenceError: require is not defined (in browser)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}