{"id":28157087,"url":"https://github.com/amkjs/amk-wrap","last_synced_at":"2025-05-15T08:17:43.098Z","repository":{"id":57177328,"uuid":"101127288","full_name":"amkjs/amk-wrap","owner":"amkjs","description":"function wrapper to catch errors in express.js controllers","archived":false,"fork":false,"pushed_at":"2024-03-13T07:29:26.000Z","size":39,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T12:39:56.446Z","etag":null,"topics":["amkjs","error-handler","error-wrapping","express"],"latest_commit_sha":null,"homepage":"","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/amkjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-08-23T02:14:21.000Z","updated_at":"2024-05-28T05:46:43.000Z","dependencies_parsed_at":"2024-03-13T08:49:49.740Z","dependency_job_id":null,"html_url":"https://github.com/amkjs/amk-wrap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amkjs%2Famk-wrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amkjs%2Famk-wrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amkjs%2Famk-wrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amkjs%2Famk-wrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amkjs","download_url":"https://codeload.github.com/amkjs/amk-wrap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301583,"owners_count":22047907,"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":["amkjs","error-handler","error-wrapping","express"],"created_at":"2025-05-15T08:16:10.476Z","updated_at":"2025-05-15T08:17:43.090Z","avatar_url":"https://github.com/amkjs.png","language":"JavaScript","readme":"# AMK-WRAP\r\n\r\n[![Github Actions](https://github.com/amkjs/amk-wrap/actions/workflows/node.js.yml/badge.svg)](https://github.com/amkjs/amk-wrap/actions/workflows/node.js.yml)\r\n[![codecov](https://codecov.io/github/amkjs/amk-wrap/graph/badge.svg?token=bgxufudUco)](https://codecov.io/github/amkjs/amk-wrap)\r\n[![Known Vulnerabilities](https://snyk.io/test/github/amkjs/amk-wrap/badge.svg?targetFile=package.json)](https://snyk.io/test/github/amkjs/amk-wrap?targetFile=package.json)\r\n\r\nfunction wrapper to catch errors in [express](https://expressjs.com/) controllers\r\n\r\n## Usage\r\n\r\nto install: `npm i amk-wrap`\r\n\r\ncan pass a function or a class method.\r\n\r\non the router file:\r\n```\r\nconst express = require('express');\r\nconst router = express.Router();\r\nconst wrap = require('amk-wrap');\r\n\r\nclass Controller {\r\n  constructor() {\r\n    this.something = \"something\"\r\n  }\r\n  async get(req, res) {\r\n    this.something; // access this\r\n    res.send('hello world');\r\n  }\r\n}\r\nconst controller = new Controller();\r\nmodule.exports = function (controller) {\r\n  router.get('/', wrap(controller, 'get')); // pass a class method\r\n  return router;\r\n}\r\n\r\n```\r\n\r\non the index.js:\r\n```\r\nconst wrap = require('amk-wrap');\r\n\r\n// some other code\r\n\r\napp.get('/', wrap(getFunction)); // pass a function\r\n```\r\nor\r\n```\r\nconst wrap = require('amk-wrap');\r\n\r\n// some other code\r\n\r\napp.get('/', wrap((req, res) =\u003e {\r\n\tres.send('hello world');\r\n}));\r\n```\r\n\r\n## Tests\r\n1. install dependencies using `npm install`\r\n2. run `npm test`\r\n\r\n## Feedback\r\n\r\nAll bugs, feature requests, pull requests, feedback, etc., are welcome. [Create an issue](https://github.com/amkjs/amk-wrap/issues).\r\n\r\n## License\r\n[MIT](https://github.com/amkjs/amk-wrap/blob/master/LICENSE)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famkjs%2Famk-wrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famkjs%2Famk-wrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famkjs%2Famk-wrap/lists"}