{"id":15686285,"url":"https://github.com/magicdawn/express-modern","last_synced_at":"2025-05-07T18:23:28.099Z","repository":{"id":75520027,"uuid":"54398332","full_name":"magicdawn/express-modern","owner":"magicdawn","description":"use async function or generator function with express","archived":false,"fork":false,"pushed_at":"2022-11-04T09:52:58.000Z","size":43,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T12:58:03.336Z","etag":null,"topics":[],"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/magicdawn.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":"2016-03-21T15:01:24.000Z","updated_at":"2023-05-19T02:29:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd31e5ea-8e9c-406c-b9aa-d6f33005cb05","html_url":"https://github.com/magicdawn/express-modern","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.10526315789473684","last_synced_commit":"c6f12bd3e505120fe6ac41ebad5fcad64aaef1b8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicdawn%2Fexpress-modern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicdawn%2Fexpress-modern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicdawn%2Fexpress-modern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicdawn%2Fexpress-modern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magicdawn","download_url":"https://codeload.github.com/magicdawn/express-modern/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252932247,"owners_count":21827260,"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-10-03T17:37:33.393Z","updated_at":"2025-05-07T18:23:28.079Z","avatar_url":"https://github.com/magicdawn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-modern\n\nuse async function or generator function with express\n\n[![Build Status](https://img.shields.io/travis/magicdawn/express-modern.svg?style=flat-square)](https://travis-ci.org/magicdawn/express-modern)\n[![Coverage Status](https://img.shields.io/coveralls/magicdawn/express-modern.svg?style=flat-square)](https://coveralls.io/github/magicdawn/express-modern?branch=master)\n[![npm version](https://img.shields.io/npm/v/express-modern.svg?style=flat-square)](https://www.npmjs.com/package/express-modern)\n[![npm downloads](https://img.shields.io/npm/dm/express-modern.svg?style=flat-square)](https://www.npmjs.com/package/express-modern)\n[![npm license](https://img.shields.io/npm/l/express-modern.svg?style=flat-square)](http://magicdawn.mit-license.org)\n\n## Install\n\n```js\nnpm i express-modern --save\n```\n\n## supported case\n\n- normal handler `app.get('/', modern((req, res, next) =\u003e { ... }))`\n- error handler `app.get('/', modern((err, req, res, next) =\u003e { ... }))`\n- param handler `app.param('user', modern((req, res, next, user) =\u003e { ... }))`\n\n## API\n\n```js\nconst modern = require('express-modern')\n```\n\n### generator function\n\n```js\nconst app = express();\napp.get('/', modern(function * (req, res, next) {\n  yield new Promise(r =\u003e setTimeout(r, 10));\n  res.send('generator function');\n}));\n\nconst res = yield request(app)\n  .get('/')\n  .endAsync();\nres.text.should.match(/generator/);\n```\n\nthe generator function will be wrap via `co.wrap`. and the `modern` function\nwill take care of the arity of the handler. see http://expressjs.com/en/guide/error-handling.html\n\n### async function\n\n```js\nconst app = express();\napp.get('/', modern(async function(req, res, next) {\n  await new Promise(r =\u003e setTimeout(r, 10));\n  res.send('async function');\n}));\n\nconst res = yield request(app)\n  .get('/')\n  .endAsync();\nres.text.should.match(/async/);\n```\n\nthe async function will be called \u0026 the rejected value will be passed to `next` automatically\n\n### normal function\n\n```js\nconst app = express();\napp.get('/', modern((req, res, next) =\u003e {\n  res.send('normal function');\n}));\n\nconst res = yield request(app)\n  .get('/')\n  .endAsync();\n\nres.text.should.match(/normal/);\n```\n\nthe `modern` function does nothing on normal function.\n\n## Changelog\n\n[CHANGELOG.md](CHANGELOG.md)\n\n## License\n\nthe MIT License http://magicdawn.mit-license.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagicdawn%2Fexpress-modern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagicdawn%2Fexpress-modern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagicdawn%2Fexpress-modern/lists"}