Registry / web-framework / express-prettify

express-prettify

JSON →
library0.1.2jsnpmunverified

express-prettify is an Express.js middleware designed to automatically format (pretty-print) JSON responses based on the presence of a specified query parameter in the request URL. This enables developers to easily get human-readable API output for debugging or inspection by adding, for instance, `?pretty` to their requests, while standard minified JSON is returned otherwise. The current stable version is 0.1.2. However, the package has not seen significant updates since 2018, indicating an effectively abandoned status. It differentiates itself by offering a simple, client-controlled mechanism for JSON formatting without requiring server-side changes to every `res.json()` call or a global configuration.

npm install express-prettify
INSTALL
IMPORT
SIG · EXPRESS-PRETTIFY
E
express-prettify
web-frameworkjavascriptv0.1.2
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.

pretty
const pretty = require('express-prettify');
import pretty from 'express-prettify';
This package is CommonJS-only. Using `import` syntax in an ES Modules project will lead to runtime errors, as it does not expose an `exports` field or default ESM export.

Demonstrates how to integrate `express-prettify` middleware into an Express application, enabling pretty-printed JSON responses when the `pretty` query parameter is present in the URL, and regular minified JSON otherwise.

"use strict"; const express = require('express'); const app = express(); const pretty = require('express-prettify'); // Configure the middleware to pretty print when the 'pretty' query parameter is present app.use(pretty({ query: 'pretty' })); app.get('/', function(req, res) { res.json({ hello: 'world', message: 'This is pretty printed JSON if ?pretty is in the URL', data: { id: 1, type: 'example', value: Math.random() } }); }); const PORT = 3000; app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log(`Try: curl http://localhost:${PORT}?pretty`); console.log(`Try: curl http://localhost:${PORT}`); });
Debug
Known issues
gotchaThis package is CommonJS-only and incompatible with native ES Modules (ESM) environments. Direct `import` statements will fail.
fix
For ESM projects, ensure your `package.json` specifies `"type": "commonjs"` or dynamically import with `const pretty = await import('express-prettify')` (though not officially supported and should be avoided if possible). Consider using an ESM-compatible alternative.
affects: >=0.1.0
gotchaThe `express-prettify` package appears to be abandoned, with no significant updates or maintenance since 2018. This implies potential security vulnerabilities, lack of new features, and incompatibility with newer Node.js or Express versions.
fix
Consider evaluating alternative, actively maintained Express middleware for JSON pretty-printing if long-term support, security patches, or new features are required.
affects: >=0.1.0
gotchaThis middleware overrides `res.json()`. If other middleware in your application also modify `res.json()`, their order of execution matters and might lead to unexpected behavior or conflicts.
fix
Ensure `express-prettify` is placed appropriately in your middleware chain, typically after body parsers but before any middleware that specifically relies on or modifies `res.json()` functionality.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'call')
Attempting to `import` `express-prettify` in an ES Modules environment when the package is CommonJS-only.
fix
Use `const pretty = require('express-prettify');` and ensure your environment is configured for CommonJS, or use a dynamic `import()` as a workaround: `const pretty = (await import('express-prettify')).default;`.
JSON output is not pretty-printed even when the query parameter is present in the URL.
The configured query parameter does not match the URL, or the `express-prettify` middleware is not applied correctly or in the right order.
fix
Double-check that the `query` option in `pretty({ query: 'yourParam' })` exactly matches the query parameter you're using in the URL (e.g., `?yourParam`). Ensure `app.use(pretty(...))` is called before any routes that send JSON responses.
TypeError: app.use is not a function
The `express()` factory function was called without assigning its result (the Express application instance) to the `app` variable.
fix
Ensure your Express application instance is correctly initialized: `const app = require('express')();`
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
expressrequiredRequired runtime dependency for the middleware to function within an Express application.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
express-prettify — npm install express-prettify · libregistry