{"id":17631,"library":"express-prettify","title":"Express JSON Prettifier Middleware","description":"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.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/stoshiya/express-prettify","tags":["javascript","express","pretty","json"],"install":[{"cmd":"npm install express-prettify","lang":"bash","label":"npm"},{"cmd":"yarn add express-prettify","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-prettify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required runtime dependency for the middleware to function within an Express application.","package":"express","optional":false}],"imports":[{"note":"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.","wrong":"import pretty from 'express-prettify';","symbol":"pretty","correct":"const pretty = require('express-prettify');"}],"quickstart":{"code":"\"use strict\";\n\nconst express = require('express');\nconst app = express();\nconst pretty = require('express-prettify');\n\n// Configure the middleware to pretty print when the 'pretty' query parameter is present\napp.use(pretty({ query: 'pretty' }));\n\napp.get('/', function(req, res) {\n  res.json({ \n    hello: 'world',\n    message: 'This is pretty printed JSON if ?pretty is in the URL',\n    data: { id: 1, type: 'example', value: Math.random() }\n  });\n});\n\nconst PORT = 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log(`Try: curl http://localhost:${PORT}?pretty`);\n  console.log(`Try: curl http://localhost:${PORT}`);\n});","lang":"javascript","description":"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."},"warnings":[{"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.","message":"This package is CommonJS-only and incompatible with native ES Modules (ESM) environments. Direct `import` statements will fail.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider evaluating alternative, actively maintained Express middleware for JSON pretty-printing if long-term support, security patches, or new features are required.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"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;`.","cause":"Attempting to `import` `express-prettify` in an ES Modules environment when the package is CommonJS-only.","error":"TypeError: Cannot read properties of undefined (reading 'call')"},{"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.","cause":"The configured query parameter does not match the URL, or the `express-prettify` middleware is not applied correctly or in the right order.","error":"JSON output is not pretty-printed even when the query parameter is present in the URL."},{"fix":"Ensure your Express application instance is correctly initialized: `const app = require('express')();`","cause":"The `express()` factory function was called without assigning its result (the Express application instance) to the `app` variable.","error":"TypeError: app.use is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}