{"id":21031563,"url":"https://github.com/slaveofcode/express-multi-hijack","last_synced_at":"2025-07-22T11:03:08.824Z","repository":{"id":92795017,"uuid":"371320209","full_name":"slaveofcode/express-multi-hijack","owner":"slaveofcode","description":"Simply hijack your express response via middleware.","archived":false,"fork":false,"pushed_at":"2021-05-27T11:27:49.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-30T08:33:02.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/slaveofcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-27T09:35:56.000Z","updated_at":"2021-05-29T13:15:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"6664a22c-2b56-4513-a52f-191551f6d74b","html_url":"https://github.com/slaveofcode/express-multi-hijack","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/slaveofcode/express-multi-hijack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fexpress-multi-hijack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fexpress-multi-hijack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fexpress-multi-hijack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fexpress-multi-hijack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slaveofcode","download_url":"https://codeload.github.com/slaveofcode/express-multi-hijack/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slaveofcode%2Fexpress-multi-hijack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266481713,"owners_count":23935935,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-19T12:29:15.193Z","updated_at":"2025-07-22T11:03:08.795Z","avatar_url":"https://github.com/slaveofcode.png","language":"TypeScript","readme":"# Express Multi Hijack\n\nSimply hijack or intercept your express response via middleware.\n\n## Installation\n\n\u003e npm i express-multi-hijack\n\n## How it works\n\nThis library works by overriding `res.end` function, still maintaining the original one once all of the \"hijack\" functions are executed.\n\nSo it is safe to use with Your own custom `res.end` implementation.\n\n## Example\n\n\n1. Simple Tracing Response Body\n```js\nconst Express = require('express');\nconst { Hijack } = require('express-multi-hijack');\n\nconst app = Express()\n\napp.use(Hijack({\n  json: true,\n  handler: (body, req, res, next) =\u003e {\n    console.info('got response body', body) // { \"foo\": \"bar\" }\n  }\n}))\n\napp.get('/bar', (req, res, next) =\u003e {\n  res.json({\n    bar: 'foo',\n  })\n})\n\napp.get('/foo', (req, res, next) =\u003e {\n  res.json({\n    foo: 'bar',\n  })\n})\n\napp.listen(8080)\n```\n\nBased on the example above, the hijack handler will print `{ \"foo\": \"bar\" }` on request to [localhost:8080/foo](http://localhost:8080/foo) and `{ \"bar\": \"foo\" }` when requesting to [localhost:8080/bar](http://localhost:8080/bar).\n\n2. Intercept and Override Response Body\n\n```js\nconst Express = require('express')\nconst { Hijack } = require('../dist')\n\nconst app = Express()\n\napp.use(Hijack({\n  json: true,\n  handler: (body, _, res) =\u003e {\n    console.info('body:', body)\n    res.json({ message: 'Today is the bad day' })\n  }\n}))\n\napp.get('/', (_, res) =\u003e {\n  return res.json({ message: 'Today is a Great Day!' })\n})\n\napp.listen(8080)\n```\n\nThe code above will change the response `message` from `'Today is a Great Day!'` to `'Today is the bad day'`\n\n3. Multiple Hijack, early hijack function is the highest priority\n\n```js\nconst Express = require('express')\nconst { Hijack } = require('../dist')\n\nconst app = Express()\n\n// hijack on monday\napp.use(Hijack({\n  json: true,\n  handler: (body, _, res) =\u003e {\n    if (body.today === 'Monday') {\n      res.json({\n        ...body,\n        message: 'What a lazy day'\n      })\n    }\n  }\n}))\n\n// hijack on friday\napp.use(Hijack({\n  json: true,\n  handler: (body, req, res) =\u003e {\n    if (req.path === '/friday') {\n      res.json({\n        ...body,\n        message: 'What a wondeful day'\n      })\n    }\n  }\n}))\n\napp.get('/', (_, res) =\u003e res.json({ message: 'No Hijack' }))\n\napp.get('/monday', (_, res) =\u003e {\n  return res.status(200).json({ today: 'Monday', message: 'Today is a Great Day!' })\n})\n\napp.get('/friday', (_, res) =\u003e {\n  return res.status(200).json({ message: 'Today is a Great Day!' })\n})\n\napp.listen(8080)\n\nThe code above will intercept and change response for [localhost:8080/monday](http://localhost:8080/monday) to `{today: 'Moday', message: 'What a lazy day'}`, and [localhost:8080/friday](http://localhost:8080/friday) to `{message: 'What a wondeful day'}`\n```\n\n\nFor more examples please visit [example](https://github.com/slaveofcode/express-multi-hijack/tree/master/example) directory.\n\n## LICENSE\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslaveofcode%2Fexpress-multi-hijack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslaveofcode%2Fexpress-multi-hijack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslaveofcode%2Fexpress-multi-hijack/lists"}