Registry / web-framework / mollify

mollify

JSON →
library6.0.0jsnpmunverified

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.

npm install mollify
INSTALL
IMPORT
SIG · MOLLIFY
M
mollify
web-frameworkjavascriptv6.0.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.

mollify
import mollify from 'mollify';
const mollify = require('mollify');
Mollify transitioned to pure ESM in v5.0.0, making `require()` unusable for versions 5 and above. This is a default export.
fileURLToPath
import { fileURLToPath } from 'url';
const { fileURLToPath } = require('url');
Required in ESM contexts to correctly resolve file paths, especially when recreating CommonJS `__filename`.
dirname
import { dirname } from 'path';
const { dirname } = require('path');
Used in conjunction with `fileURLToPath` to replicate CommonJS `__dirname` functionality in ESM.

This quickstart demonstrates setting up an Express server that uses mollify middleware to serve minified static content from the current directory.

import {fileURLToPath} from 'url'; import {dirname} from 'path'; import http from 'http'; import mollify from 'mollify'; import express from 'express'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const app = express(); const server = http.createServer(app); const port = process.env.PORT ?? 1337; const ip = process.env.IP ?? '0.0.0.0'; app.use(mollify({ dir: __dirname, is: true, // default })); app.use(express.static(__dirname)); server.listen(port, ip, () => { console.log(`Server listening on http://${ip}:${port}`); console.log(`Serving static files from: ${__dirname}`); });
Debug
Known issues
breakingVersion 6.0.0 dropped support for Node.js versions older than 16. Ensure your environment meets this requirement before upgrading.
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).
affects: >=6.0.0
breakingVersion 5.0.0 converted the package to pure ESM. CommonJS `require()` statements will no longer work, and you must use `import` syntax.
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'`.
affects: >=5.0.0
breakingVersion 4.0.0 dropped support for Node.js versions older than 14.
fix
Upgrade Node.js to version 14 or higher.
affects: >=4.0.0 <5.0.0
breakingVersion 3.0.0 dropped support for Node.js versions older than 12.
fix
Upgrade Node.js to version 12 or higher.
affects: >=3.0.0 <4.0.0
Errors
Common errors & fixes
TypeError: mollify is not a function
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.
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.
ReferenceError: __dirname is not defined
Using `__dirname` or `__filename` directly in an ESM module without defining them, as they are CommonJS-specific globals.
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);`
Files are not being minified (but mollify is enabled)
The `dir` option passed to mollify does not correctly point to the directory containing the static files, or `is: false` is explicitly set.
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.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
minifyrequiredCore dependency for the minification functionality.
expressoptionalCommonly used web framework for which mollify serves as middleware, as shown in examples.
Agent activity
2 hits · last 30 days
node
2
Resources
mollify — npm install mollify · libregistry