{"library":"on-http-end","title":"Capture HTTP Response Content","description":"on-http-end is a lightweight Node.js utility designed to intercept and capture the full HTTP response payload, including headers, status code, and the final data, just before the response stream concludes. Inspired by `apicache`, it offers a simple, callback-based API to register a function that executes when `res.end()` is called. This allows developers to inspect or process the complete response content and metadata, making it suitable for logging, debugging, or custom caching mechanisms. The current stable version is 1.0.3, which includes a fix for proper scope handling, allowing multiple `onEnd` registrations on a single response object. Its release cadence appears infrequent, reflecting its focused scope and stable API. A key differentiator is its direct, low-level integration with Node.js's native `http.ServerResponse` object, providing granular control without the overhead of a full middleware framework.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install on-http-end"],"cli":null},"imports":["const onEnd = require('on-http-end')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const onEnd = require('on-http-end')\nconst http = require('http')\n\nconst server = http.createServer((req, res) => {\n  onEnd(res, (payload) => {\n    // The payload object contains status, headers, data, and encoding\n    console.log('Captured Response Payload:', payload)\n    // Example: Log only the data\n    // console.log('Response data:', payload.data)\n  })\n\n  res.setHeader('x-custom-header', 'captured-value')\n  res.statusCode = 201;\n  res.end('Hello, on-http-end user!', 'utf-8')\n})\n\nserver.listen(3000, () => {\n  console.log('Server listening on http://localhost:3000')\n  console.log('Try visiting http://localhost:3000 in your browser.')\n})","lang":"javascript","description":"Demonstrates how to integrate `on-http-end` with a basic Node.js HTTP server to capture response details.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}