Registry / devops / express-beautifier

express-beautifier

JSON →
library0.1.4jsnpmunverified

Express.js middleware that beautifies or minifies HTML, JS, and CSS output from any template engine. Current stable version is 0.1.4 (last released in 2022). It wraps js-beautify and html-minifier to provide human-readable output in development and minified output in production. Intended as a maintained fork of the unmaintained express-beautify package. It supports custom options for both beautification and minification, and provides helper methods like res.sendHTML, res.sendJS, res.sendCSS.

npm install express-beautifier
INSTALL
IMPORT
SIG · EXPRESS-BEAUTIFIER
E
express-beautifier
devopsjavascriptv0.1.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
import expressBeautify from 'express-beautify'
const expressBeautify = require('express-beautify')
Since v0.1.0, package uses default export. CommonJS require works but TypeScript ESM import is recommended.
minify
import { minify } from 'express-beautify'
const minify = require('express-beautify').minify
Named export for minify middleware. In CJS, destructure from require.
expressBeautify (with options)
import createBeautifier from 'express-beautify'; const expressBeautify = createBeautifier({indent_size: 4})
const expressBeautify = new (require('express-beautify'))({indent_size: 4})
The default export is a factory function that accepts options and returns middleware.

Demonstrates importing express-beautify, creating beautify middleware with options, using res.sendHTML, and setting up minify middleware.

import express from 'express'; import createBeautifier from 'express-beautify'; const app = express(); // Use beautify middleware const beautify = createBeautifier({ indent_size: 2 }); app.use(beautify); app.get('/', (req, res) => { res.sendHTML('<div>Hello <span>World</span></div>'); }); // For minify in production import { minify } from 'express-beautify'; const min = minify({ collapseWhitespace: true }); app.use(min); app.listen(3000);
Debug
Known issues
breakingPackage renamed from express-beautify to express-beautifier; imports changed accordingly.
fix
Replace all instances of 'express-beautify' with 'express-beautifier' in import statements.
affects: >=0.1.0
deprecatedres.sendHTML, res.sendJS, res.sendCSS are non-standard Express methods added by this middleware; they may conflict with other middleware.
fix
Use standard res.send or res.render instead, or manually handle formatting.
affects: >=0.1.0
gotchaThe middleware must be used BEFORE routes that send HTML/JS/CSS; otherwise it will not process the output.
fix
Ensure app.use(beautify) is placed before route definitions.
affects: >=0.1.0
gotchaMinify and beautify cannot be used simultaneously; using both will cause unpredictable results.
fix
Use only one of the two middleware in a given request chain. Typically beautify for dev, minify for prod.
affects: >=0.1.0
deprecatedThe package is based on an unmaintained fork; updates to js-beautify or html-minifier may not be reflected.
fix
Consider using js-beautify and html-minifier directly in your own middleware for more control.
affects: >=0.1.0
gotchaOptions passed to factory are global; cannot change per-request.
fix
Create separate middleware instances for different routes if different options are needed.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'express-beautify'
Installing express-beautifier but importing as express-beautify
fix
Change import to 'express-beautifier' or vice versa.
expressBeautify is not a function
Misunderstanding default export; trying to use require('express-beautify') as a constructor
fix
Use `const expressBeautify = require('express-beautify');` and then call `expressBeautify({...})`.
TypeError: res.sendHTML is not a function
Middleware not applied before route handler
fix
Place `app.use(beautify)` before the route definition.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
expressrequiredpeer dependency for middleware usage
js-beautifyrequiredcore engine for beautification
html-minifierrequiredcore engine for minification
Agent activity
6 hits · last 30 days
node
4
Resources
express-beautifier — npm install express-beautifier · libregistry