{"id":17815,"library":"mollify","title":"Mollify Node.js Minify Middleware","description":"Mollify is a Node.js middleware that integrates the `minify` package, providing on-the-fly minification of static assets like JavaScript, CSS, and HTML files. It is primarily designed for use with web frameworks such as Express, streamlining the process of serving optimized content. The current stable version is 6.0.0, released after several iterative updates that include dropping support for older Node.js versions (now requiring Node.js >=16) and a significant transition to ESM in version 5.0.0. The package has a moderate release cadence, often driven by updates to its core `minify` dependency or environmental changes. Its key differentiator lies in its straightforward integration as an Express middleware, offering a simple solution for asset optimization without requiring complex build pipelines, making it suitable for rapid development and certain production environments.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/coderaiser/node-mollify","tags":["javascript","minify","middleware"],"install":[{"cmd":"npm install mollify","lang":"bash","label":"npm"},{"cmd":"yarn add mollify","lang":"bash","label":"yarn"},{"cmd":"pnpm add mollify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for the minification functionality.","package":"minify","optional":false},{"reason":"Commonly used web framework for which mollify serves as middleware, as shown in examples.","package":"express","optional":true}],"imports":[{"note":"Mollify transitioned to pure ESM in v5.0.0, making `require()` unusable for versions 5 and above. This is a default export.","wrong":"const mollify = require('mollify');","symbol":"mollify","correct":"import mollify from 'mollify';"},{"note":"Required in ESM contexts to correctly resolve file paths, especially when recreating CommonJS `__filename`.","wrong":"const { fileURLToPath } = require('url');","symbol":"fileURLToPath","correct":"import { fileURLToPath } from 'url';"},{"note":"Used in conjunction with `fileURLToPath` to replicate CommonJS `__dirname` functionality in ESM.","wrong":"const { dirname } = require('path');","symbol":"dirname","correct":"import { dirname } from 'path';"}],"quickstart":{"code":"import {fileURLToPath} from 'url';\nimport {dirname} from 'path';\nimport http from 'http';\nimport mollify from 'mollify';\nimport express from 'express';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst app = express();\nconst server = http.createServer(app);\n\nconst port = process.env.PORT ?? 1337;\nconst ip = process.env.IP ?? '0.0.0.0';\n\napp.use(mollify({\n    dir: __dirname,\n    is: true, // default\n}));\n\napp.use(express.static(__dirname));\n\nserver.listen(port, ip, () => {\n  console.log(`Server listening on http://${ip}:${port}`);\n  console.log(`Serving static files from: ${__dirname}`);\n});","lang":"javascript","description":"This quickstart demonstrates setting up an Express server that uses mollify middleware to serve minified static content from the current directory."},"warnings":[{"fix":"Upgrade Node.js to version 16 or higher, or pin 'mollify' to a version compatible with your current Node.js (e.g., `<6.0.0` for Node.js <16).","message":"Version 6.0.0 dropped support for Node.js versions older than 16. Ensure your environment meets this requirement before upgrading.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Migrate your project to ESM if not already, or use dynamic `import()` if you need to load mollify from a CommonJS context (though this is not recommended). Update all `require('mollify')` to `import mollify from 'mollify'`.","message":"Version 5.0.0 converted the package to pure ESM. CommonJS `require()` statements will no longer work, and you must use `import` syntax.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Upgrade Node.js to version 14 or higher.","message":"Version 4.0.0 dropped support for Node.js versions older than 14.","severity":"breaking","affected_versions":">=4.0.0 <5.0.0"},{"fix":"Upgrade Node.js to version 12 or higher.","message":"Version 3.0.0 dropped support for Node.js versions older than 12.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"For mollify v5.0.0+, ensure you are using `import mollify from 'mollify';`. If in an older CommonJS context, ensure `require('mollify')` is used correctly as a function.","cause":"Attempting to use `require('mollify')` in an ESM context, or calling `mollify` directly when it might be a default export that needs `mollify.default` in some mixed setups, or `require` in an ESM module.","error":"TypeError: mollify is not a function"},{"fix":"Use the provided ESM boilerplate to define `__filename` and `__dirname` from `import.meta.url`: `import {fileURLToPath} from 'url'; import {dirname} from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename);`","cause":"Using `__dirname` or `__filename` directly in an ESM module without defining them, as they are CommonJS-specific globals.","error":"ReferenceError: __dirname is not defined"},{"fix":"Verify that the `dir` option in `mollify({ dir: ... })` accurately reflects the root directory where `express.static` is serving files from. Ensure `is: true` or omit the `is` property as `true` is the default.","cause":"The `dir` option passed to mollify does not correctly point to the directory containing the static files, or `is: false` is explicitly set.","error":"Files are not being minified (but mollify is enabled)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}