{"id":20809578,"url":"https://github.com/xingxingted/koa-to-express","last_synced_at":"2025-07-31T19:35:58.220Z","repository":{"id":45545745,"uuid":"92078551","full_name":"xingxingted/koa-to-express","owner":"xingxingted","description":"Use a Koa/Express middleware in an Express/Koa app","archived":false,"fork":false,"pushed_at":"2022-07-14T12:04:49.000Z","size":107,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-28T13:43:59.580Z","etag":null,"topics":["express","koa"],"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/xingxingted.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-05-22T17:05:38.000Z","updated_at":"2025-01-22T14:31:53.000Z","dependencies_parsed_at":"2022-09-05T16:00:17.780Z","dependency_job_id":null,"html_url":"https://github.com/xingxingted/koa-to-express","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xingxingted%2Fkoa-to-express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xingxingted%2Fkoa-to-express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xingxingted%2Fkoa-to-express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xingxingted%2Fkoa-to-express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xingxingted","download_url":"https://codeload.github.com/xingxingted/koa-to-express/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839294,"owners_count":21812090,"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","koa"],"created_at":"2024-11-17T20:14:35.915Z","updated_at":"2025-05-07T08:11:07.695Z","avatar_url":"https://github.com/xingxingted.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-to-express\n\n[![Build Status](https://travis-ci.org/xingxingted/koa-to-express.svg?branch=master)](https://travis-ci.org/xingxingted/koa-to-express)\n[![codecov](https://codecov.io/gh/xingxingted/koa-to-express/branch/master/graph/badge.svg)](https://codecov.io/gh/xingxingted/koa-to-express)\n[![npm version](https://badge.fury.io/js/koa-to-express.svg)](https://badge.fury.io/js/koa-to-express)\n\nUse a **Koa/Express** middleware in an Express/Koa app.\n\nIt could convert a middleware to another form between Express and koa middleware.\n\n## Requirement\nKoa-to-express requires *koa@2.0.0* and *express@4.0.0* or higher.\n\nNode 7.6+ is required if you want to use ES2015's *async/await* syntax.\n\nPlease go to [koa-to-express@1.x](https://github.com/xingxingted/koa-to-express/tree/1.x) if you want to use koa1.\n\n## Installation\nNpm 5.x\n```\nnpm install koa-to-express [-P]\n```\n\nOthers\n```\nnpm install koa-to-express -S\n```\n\n## Usage\n\n```\nconst k2e       = require('koa-to-express');\n\nconst koaMiddleware = (ctx, next) =\u003e {\n    ctx.body = 'hello world';\n    return next();\n};\n\nrequire('express')().use(k2e(koaMiddleware)).listen(3000);\n\n// curl localhost:3000/\n// output: hello world\n```\n\n## API\n\n### koaToExpress[.koaToExpress]\\(middleware)\n\n- **middleware** : `Function|Array\u003cFunction\u003e`\n\n****\n\n* Convert Koa middleware(s) into an Express middleware and return it.\n\n* Note that the second parameter (usually named as \"next\") passed to the last one of the middlewares is `() =\u003e Promise.resolve()`, because the cascading categories between [Koa](https://github.com/koajs/koa/blob/master/docs/api/index.md#cascading) and [Express](http://expressjs.com/en/guide/writing-middleware.html) are different and the end of the rest Express middlewares executing can't be informed back.\n\n* It means that, resolving or rejecting the Koa middleware(s), which will return a resolved or rejected promise, will call the next middleware (as calling the Express's `next()`) or throw out an error (as calling the `next(err)`).\n\n### koaToExpress.expressToKoa(middleware)\n\n- **middleware** : `Function|Array\u003cFunction\u003e`\n\n****\n\n* Convert Express middleware(s) into a Koa middleware and return it.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxingxingted%2Fkoa-to-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxingxingted%2Fkoa-to-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxingxingted%2Fkoa-to-express/lists"}