{"id":20433503,"url":"https://github.com/masquerade-circus/express-response-handler","last_synced_at":"2025-12-01T18:02:38.592Z","repository":{"id":80233108,"uuid":"80777194","full_name":"Masquerade-Circus/express-response-handler","owner":"Masquerade-Circus","description":"JSend compatible response handler for Express.","archived":false,"fork":false,"pushed_at":"2020-03-14T03:12:19.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-13T21:17:18.746Z","etag":null,"topics":["express","handler","http","jsend","json","middleware","response"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Masquerade-Circus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["Masquerade-Circus"],"custom":["https://www.paypal.me/masqueradecircus"]}},"created_at":"2017-02-02T23:01:57.000Z","updated_at":"2020-03-14T03:12:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"df524136-70a6-4359-af04-66b029c123be","html_url":"https://github.com/Masquerade-Circus/express-response-handler","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.0625,"last_synced_commit":"71ed46449ee1cbb64eb9d2f2f27c1e6fd5aad571"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masquerade-Circus%2Fexpress-response-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masquerade-Circus%2Fexpress-response-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masquerade-Circus%2Fexpress-response-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Masquerade-Circus%2Fexpress-response-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Masquerade-Circus","download_url":"https://codeload.github.com/Masquerade-Circus/express-response-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241975983,"owners_count":20051559,"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":["express","handler","http","jsend","json","middleware","response"],"created_at":"2024-11-15T08:19:24.483Z","updated_at":"2025-12-01T18:02:38.541Z","avatar_url":"https://github.com/Masquerade-Circus.png","language":"JavaScript","readme":"# express-response-handler\n\nJSend compatible response handler for Express.\n\nThis module attach default and custom responses to the express request object. The result response is implemented with a response code, stack trace and [JSend specification](https://labs.omniti.com/labs/jsend) compatible properties.\n\n## Install\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\n$ npm install express-response-handler\n# or\n$ yarn add express-response-handler\n```\n\n## Use\n\n```javascript\nvar express = require('express'),\n    responseHandler = require('express-response-handler'),\n    App = express(),\n    customCodes = [\n        ['Unauthorized', 'error', 401]\n    ];\n\nApp\n    .use(responseHandler(customCodes))\n    .get('/', (req, res) =\u003e {\n        let data = {\n            errors: []\n        };\n\n        // Recommended way\n        res.error.Unauthorized('permission.error.unauthorized', data);\n\n        // Also available with the same result\n        res.error('Unauthorized', 'permission.error.unauthorized', data);\n        res.error(401, 'permission.error.unauthorized', data);\n        res.error[401]('permission.error.unauthorized', data);\n    });\n```\n\nIf your application calls various responses, only the first one will be sent. So in the previous example only the Recommended way will be sent.\n\n## Response examples\n\nIf Accept Header is set to 'application/json':\n```javascript\n{\n  \"message\": \"permission.error.unauthorized\",\n  \"data\": {},\n  \"name\": \"Unauthorized\",\n  \"status\": \"error\",\n  \"code\": 401,\n  \"errors\": [],\n  \"stack\": \"Error\\n ...\",\n  \"time\": 187.98342 // Response time\n}\n```\n\nif no Accept Header or set to other than 'application/json':\n```\nUnauthorized: permission.error.unauthorized\n```\n\nThe stack trace will be available only when env is other than production.\n\n## Default codes attached\n\n```javascript\n/**\n * Every item follows the form\n * [@name(string), @type(string), @code(integer)]\n */\n\nlet codes = [\n    ['BadRequest', 'error', 400],\n    ['Unauthorized', 'error', 401],\n    ['PaymentRequired', 'error', 402],\n    ['Forbidden', 'error', 403],\n    ['NotFound', 'error', 404],\n    ['MethodNotAllowed', 'error', 405],\n    ['NotAcceptable', 'error', 406],\n    ['RequestTimeout', 'error', 408],\n    ['Conflict', 'error', 409],\n    ['UnprocessableEntity', 'error', 422],\n    ['TooManyRequests', 'error', 429],\n    ['ServerError', 'error', 500],\n    ['NotImplemented', 'error', 501],\n    ['BadGateway', 'error', 502],\n    ['ServiceUnavailable', 'error', 503],\n    ['OK', 'success', 200],\n    ['Created', 'success', 201],\n    ['Accepted', 'success', 202],\n    ['NoContent', 'success', 204],\n    ['ResetContent', 'success', 205],\n    ['PartialContent', 'success', 206],\n    ['Default', 'error', 500]\n]\n```\n\nAlso you can pass an array of codes to the factory function. In this way you can also overwrite the default ones.\n\n## Legal\n\nAuthor: [Masquerade Circus](http://masquerade-circus.net). License [Apache-2.0](https://opensource.org/licenses/Apache-2.0)\n","funding_links":["https://github.com/sponsors/Masquerade-Circus","https://www.paypal.me/masqueradecircus"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasquerade-circus%2Fexpress-response-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasquerade-circus%2Fexpress-response-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasquerade-circus%2Fexpress-response-handler/lists"}