{"id":17607,"library":"express-end","title":"Express Response End Event Middleware","description":"The `express-end` package provides a specific Express middleware designed to augment the default event handling on the `res` (response) object. Its primary function is to emit an `end` event whenever `res.end()` is called, crucially, even if the client connection has closed prematurely. This addresses a common limitation where the standard `finish` event on the `res` object might not reliably fire under such circumstances, preventing middleware from consistently determining when server-side processing for a request has fully concluded. This capability is useful for tasks like consistent post-request logging, resource cleanup, or metric collection. The package is currently at version `0.0.8` and has not been updated since 2016, indicating it is an abandoned project. Its core differentiator is providing a consistent signal for server-side request completion, regardless of client connection status, a problem that might be solved differently or directly in modern Express versions.","status":"abandoned","version":"0.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/alykoshin/express-end","tags":["javascript","express,middleware,mw,emit,end,event,res,finish,close,patch"],"install":[{"cmd":"npm install express-end","lang":"bash","label":"npm"},{"cmd":"yarn add express-end","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-end","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package exclusively uses CommonJS `require()` syntax as it targets Node.js versions prior to widespread ES module adoption and has not been updated for ESM.","symbol":"endMw","correct":"const endMw = require('express-end');"}],"quickstart":{"code":"'use strict';\n\nconst express = require('express');\nconst http    = require('http');\nconst endMw = require('express-end');\nconst app = express();\n\napp.use(endMw);\n\nlet count = 0;\n\napp.use(function(req, res, next) {\n  const current = ++count;\n  console.log('[%d] app.use()', current);\n\n  res.once('close',  function() {\n    console.log('[%d] app.use(): res.once(close)', current);\n  });\n\n  res.once('end',    function() {\n    console.log('[%d] app.use(): res.once(end)', current);\n  });\n\n  res.once('finish', function() {\n    console.log('[%d] app.use(): res.once(finish)', current);\n  });\n\n  next();\n});\n\n\nconst httpPort = 8080;\nconst RESPONSE_DELAY = 1000; // Milliseconds\n\napp.get('/test1', function (req, res) {\n  const result = { test: 'test' };\n  setTimeout(function() {\n    res\n      .status(200)\n      .send(result);\n  }, RESPONSE_DELAY);\n});\n\n\nconst server = http.createServer(app);\n\nserver.listen(httpPort, function () {\n  console.log('* Server listening at %s:%d', server.address().address, server.address().port);\n});\n","lang":"javascript","description":"This example demonstrates how to integrate `express-end` middleware and listen for the custom `end` event alongside standard `close` and `finish` events on the response object, showing how `end` fires consistently."},"warnings":[{"fix":"Do not use this package in modern Node.js or Express applications. Seek modern alternatives or implement custom event emission if absolutely necessary.","message":"This package is explicitly designed for very old Node.js versions (engines: '>=0.10') and has not been updated since 2016. It is highly incompatible with modern Node.js (e.g., 16+) and Express. Running it in a modern environment will likely cause errors or unexpected behavior.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Avoid monkey-patching where possible. If a similar functionality is needed, consider using libraries like `on-finished` which provide a more robust way to detect response completion, or implement a pattern that doesn't modify core Express objects directly.","message":"The middleware achieves its functionality by monkey-patching `res.end()`. This is an inherently fragile technique that can lead to conflicts with other middleware, Express internal changes, or unexpected side effects, especially in complex applications or when using other response-modifying libraries.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Investigate if newer Express versions (e.g., 4.x and above) provide better event handling or if alternative packages like `on-finished` offer a more reliable solution for detecting when a response has fully completed its server-side processing.","message":"The problem this package aims to solve (the `finish` event not firing when a client disconnects prematurely) might be handled differently or natively improved in newer versions of Express or related Node.js modules. Relying on this package for modern applications is considered an anti-pattern.","severity":"deprecated","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `express` is installed (`npm install express`) and `app = express();` is correctly initialized before `app.use(endMw);`.","cause":"Attempting to use `express-end` in an environment where `app` is not a valid Express application instance, or if `express` itself is not properly installed or imported.","error":"TypeError: app.use is not a function"},{"fix":"Thoroughly test `express-end` in isolation and with all other middleware. If conflicts arise, consider replacing `express-end` with a more modern and less intrusive solution like `on-finished`, which provides a callback when the response finishes or the client disconnects.","cause":"This is a consequence of the monkey-patching approach of `express-end` potentially conflicting with other middleware that also modifies `res.end()`, or due to changes in Express's internal `res` object structure in newer versions, leading to silent failures.","error":"The 'end' event does not fire consistently, or conflicts with other response handling."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}