{"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,"search_vec":"'0.0.8':110 '2016':117 'abandon':122 'address':51 'augment':18 'call':40 'capabl':88 'circumst':70 'cleanup':100 'client':45,140 'close':48,165 'collect':103 'common':53 'complet':137 'conclud':86 'connect':46,141 'consist':74,94,130 'core':125 'crucial':41 'current':107 'default':20 'design':16 'determin':75 'differ':149 'differenti':126 'direct':151 'emit':33,160 'end':3,9,35,161 'even':42 'event':4,21,36,59,162 'express':1,8,14,154,157 'express-end':7 'finish':58,164 'fire':67 'fulli':85 'function':30 'handl':22 'indic':118 'javascript':156 'like':93 'limit':54 'log':98 'metric':102 'middlewar':5,15,72,158 'might':64,146 'modern':153 'mw':159 'object':27,63 'packag':10,105 'patch':166 'post':96 'post-request':95 'prematur':49 'prevent':71 'primari':29 'problem':144 'process':80 'project':123 'provid':11,128 'regardless':138 'reliabl':66 'request':83,97,136 'res':25,62,163 'res.end':38 'resourc':99 'respons':2,26 'server':78,134 'server-sid':77,133 'side':79,135 'signal':131 'sinc':116 'solv':148 'specif':13 'standard':57 'status':142 'task':92 'updat':115 'use':90 'version':109,155 'whenev':37","created_at":"2026-04-23T17:47:10.159688+00:00","updated_at":"2026-04-23T17:47:10.159688+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/alykoshin/express-end","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/express-end","openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-22","install_tag":null}}