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-prettifyVerified import paths — ran on the pinned version, not inferred.
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.
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.Consider evaluating alternative, actively maintained Express middleware for JSON pretty-printing if long-term support, security patches, or new features are required.
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.
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;`.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.Ensure your Express application instance is correctly initialized: `const app = require('express')();`