{"id":22428412,"url":"https://github.com/momsfriendlydevco/express-events","last_synced_at":"2025-03-27T06:43:46.194Z","repository":{"id":57127882,"uuid":"210748890","full_name":"MomsFriendlyDevCo/express-events","owner":"MomsFriendlyDevCo","description":"Improved event emitter for express","archived":false,"fork":false,"pushed_at":"2019-09-30T02:31:36.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T12:50:54.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MomsFriendlyDevCo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-25T03:37:00.000Z","updated_at":"2019-09-30T02:31:38.000Z","dependencies_parsed_at":"2022-08-31T17:21:10.726Z","dependency_job_id":null,"html_url":"https://github.com/MomsFriendlyDevCo/express-events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexpress-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexpress-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexpress-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexpress-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MomsFriendlyDevCo","download_url":"https://codeload.github.com/MomsFriendlyDevCo/express-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245798538,"owners_count":20673901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T20:14:42.877Z","updated_at":"2025-03-27T06:43:46.173Z","avatar_url":"https://github.com/MomsFriendlyDevCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@MomsFriendlyDevCo/Express-Events\n=================================\nImproved event emitter for express.\n\nThis module adds a simple middleware function which transforms `res` into an event emitter and provides hookable functionality.\n\nAll events are executed via [Eventer](https://github.com/MomsFriendlyDevCo/eventer) which means all events are async friendly promisable functions which will be waited for before the emitter continues.\n\n\n```javascript\nvar express = require('express');\nvar expressEvents = require('@momsfriendlydevco/express-events');\n\nvar app = express();\n\n// Add into all requests from root onwards (use a prefix to limit)\napp.use(expressEvents());\n\n\n// Log how all endpoints took to respond\napp.use((req, res, next) =\u003e {\n\tvar startTime = Date.now();\n\tres.on('end', ()=\u003e {\n\t\tconsole.log('HIT', req.path, 'took', Date.now() - startTime, 'ms');\n\t});\n});\n\n\n// Log how big the output of any buffer response was\napp.use('/buffers', (req, res, next) =\u003e {\n\tres.on('send', output =\u003e {\n\t\tif (Buffer.isBuffer(output)) console.log('Buffered output for endpoint', req.path, 'is', buffer.length, 'bytes');\n\t\treturn output; // Pass output to actual outputter\n\t});\n\tnext();\n});\n\n\n// Glue `{status: 'goodbye'}` onto the end of all JSON requests\napp.use('/api', (req, res, next) =\u003e {\n\tres.on('json', payload =\u003e {...payload, status: 'goodbye'});\n\tnext();\n});\n```\n\n\nAPI\n===\n\nEvent: end(...args)\n-------------------\nEmitted when `res.end()` gets called with the original arguments.\n\n\nEvent: json(payload)\n--------------------\nEmitted on each call to `res.json()` with the original object payload. Subsequent functions can mutate the output before outputting.\n\n```javascript\napp.get('/api/test/json', (req, res) =\u003e {\n\tres.on('json', payload =\u003e ({...payload, bar: 'Bar!'})) // Glue 'bar' key onto output\n\tres.send({foo: 'Foo!']) // Eventually outputs {foo: 'Foo!', bar: 'Bar!'}\n});\n```\n\n\nEvent: redirect(url)\n--------------------\nEmitted on each call to `res.redirect()` with the original URL payload.\n\n\nEvent: sendFile(stream)\n-----------------------\nEmitted on each call to `res.sendFile()` with the read stream.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fexpress-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomsfriendlydevco%2Fexpress-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fexpress-events/lists"}