{"id":28054118,"url":"https://github.com/yourtion/express-coroutine","last_synced_at":"2026-02-07T12:01:12.469Z","repository":{"id":57231802,"uuid":"81153955","full_name":"yourtion/express-coroutine","owner":"yourtion","description":"Generator function and Async function to be used as middlewares in express like koa.","archived":false,"fork":false,"pushed_at":"2020-05-23T12:15:16.000Z","size":87,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-02T01:14:59.250Z","etag":null,"topics":["async","async-await","async-functions","coroutine","express","generator","koa","middleware","promise","yield"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/express-coroutine","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/yourtion.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":"2017-02-07T01:52:30.000Z","updated_at":"2019-06-07T01:36:13.000Z","dependencies_parsed_at":"2022-09-04T17:31:45.693Z","dependency_job_id":null,"html_url":"https://github.com/yourtion/express-coroutine","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/yourtion/express-coroutine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yourtion%2Fexpress-coroutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yourtion%2Fexpress-coroutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yourtion%2Fexpress-coroutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yourtion%2Fexpress-coroutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yourtion","download_url":"https://codeload.github.com/yourtion/express-coroutine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yourtion%2Fexpress-coroutine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29193999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","async-await","async-functions","coroutine","express","generator","koa","middleware","promise","yield"],"created_at":"2025-05-12T04:56:06.022Z","updated_at":"2026-02-07T12:01:12.379Z","avatar_url":"https://github.com/yourtion.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n[![npm download][download-image]][download-url]\n[![npm license][license-image]][download-url]\n[![Greenkeeper badge](https://badges.greenkeeper.io/yourtion/express-coroutine.svg)](https://greenkeeper.io/)\n\n[npm-image]: https://img.shields.io/npm/v/express-coroutine.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/express-coroutine\n[travis-image]: https://img.shields.io/travis/yourtion/express-coroutine.svg?style=flat-square\n[travis-url]: https://travis-ci.org/yourtion/express-coroutine\n[coveralls-image]: https://img.shields.io/coveralls/yourtion/express-coroutine.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/yourtion/express-coroutine?branch=master\n[david-image]: https://img.shields.io/david/yourtion/express-coroutine.svg?style=flat-square\n[david-url]: https://david-dm.org/yourtion/express-coroutine\n[node-image]: https://img.shields.io/badge/node.js-%3E=4.0-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n[download-image]: https://img.shields.io/npm/dm/express-coroutine.svg?style=flat-square\n[download-url]: https://npmjs.org/package/express-coroutine\n[license-image]: https://img.shields.io/npm/l/express-coroutine.svg\n\n# express-coroutine\n\nGenerator function and Async function to be used as middlewares in express like koa. ( use [lei-coroutine](https://github.com/leizongmin/lei-coroutine) )\n\n## Installation\n\n```bash\nnpm install express-coroutine --save\n```\n\n## Usage\n\n### Init express\n\n```javascript\nconst express = require('express-coroutine')(require('express'));\nconst app = express();\n```\n\n### Init router\n\n```javascript\nconst express = require('express-coroutine')(require('express'));\nconst app = express();\nconst router = new express.Router();\napp.use(router);\n\nrouter.get('/', function* (req, res) {\n  res.send('it works!');\n});\n\n// also async function\nrouter.get('/', async function (req, res) {\n  res.send('it works!');\n});\n```\n\nWrite your express routes by using generator functions as middlewares. \n\n```javascript\nconst express = require('express-coroutine')(require('express'));\n\nconst app = express();\n\napp.get('/user/:id', function* (req, res) {\n  const user = yield User.findById(req.params.id);\n  res.send(user);\n})\n\napp.get('/error', function* (req, res) {\n  throw new Error('Bang!');\n});\n\n// also async function\napp.get('/user2/:id', async function* (req, res) {\n  const user = await User.findById(req.params.id);\n  res.send(user);\n});\n\napp.listen(8000);\n```\n\nYou can also define multiple generator functions just the express way.\n\n```javascript\nconst fn = function (req, res, next) {\n  return new Promise((resolve, reject) =\u003e {\n    if (req.params.user !== 'a') return reject(new Error('Bang!'));\n    resolve('a');\n  });\n};\n\nconst middleware = function* (req, res, next) {\n  yield fn(req, res, next);\n};\n\nconst middleware2 = async function (req, res, next) {\n  await fn(req, res, next);\n  next();\n};\n\napp.get('/:user', middleware, function* (req, res) {\n  res.send('it works!');\n});\n\napp.get('/:user', middleware2, async function (req, res) {\n  res.send('it works!');\n});\n```\n\nMore detail demo can be found in [test.js](test.js)\n\n### Get coroutine\n\n```javascript\nconst coroutine = require('express-coroutine').coroutine;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyourtion%2Fexpress-coroutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyourtion%2Fexpress-coroutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyourtion%2Fexpress-coroutine/lists"}