# express-to-koa

> Use express middlewares in Koa2, the one that really works.

Latest version **2.0.0** (published 2019-07-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-to-koa
pnpm add express-to-koa
yarn add express-to-koa
bun add express-to-koa
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2019-07-05 |
| First published | 2017-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/express-to-koa) |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | kaelzhang |
| Maintainers | kael |
| Keywords | express-to-koa, express, koa, koa2, middleware, converter, connect, framework |

## Links

- npm: https://www.npmjs.com/package/express-to-koa
- Repository: https://github.com/kaelzhang/express-to-koa
- Homepage: https://github.com/kaelzhang/express-to-koa#readme
- Issues: https://github.com/kaelzhang/express-to-koa/issues
- npm.io page: https://npm.io/package/express-to-koa

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads
- [@modern-js/plugin-swc](https://npm.io/package/@modern-js/plugin-swc.md) — 3.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-07-05
- 1.2.0 — 2019-05-09
- 1.1.4 — 2019-04-01
- 1.1.3 — 2019-03-29
- 1.1.2 — 2019-03-29
- 1.1.1 — 2019-03-29
- 1.1.0 — 2019-03-28
- 1.0.9 — 2019-03-28
- 1.0.8 — 2019-03-28
- 1.0.7 — 2019-03-06
- 1.0.6 — 2017-06-05
- 1.0.5 — 2017-05-25
- 1.0.4 — 2017-05-25
- 1.0.3 — 2017-03-07
- 1.0.2 — 2017-03-07
- … 3 more at https://npm.io/package/express-to-koa/versions

## README

[![Build Status](https://travis-ci.org/kaelzhang/express-to-koa.svg?branch=master)](https://travis-ci.org/kaelzhang/express-to-koa)
[![Coverage](https://codecov.io/gh/kaelzhang/express-to-koa/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/express-to-koa)

<!-- optional appveyor tst
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/express-to-koa?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/express-to-koa)
-->
<!-- optional npm downloads
[![npm module downloads per month](http://img.shields.io/npm/dm/express-to-koa.svg)](https://www.npmjs.org/package/express-to-koa)
-->
<!-- optional dependency status
[![Dependency Status](https://david-dm.org/kaelzhang/express-to-koa.svg)](https://david-dm.org/kaelzhang/express-to-koa)
-->

# express-to-koa

Use express middlewares in Koa2 (not support koa1 for now), the one that **REALLY WORKS**.

- Handle koa2 http status code, which fixes the common issue that we always get 404 with [koa-connect](https://www.npmjs.com/package/koa-connect)
- Handle express middlewares that contains `.pipe(res)`, such as `express.static` which based on [`send`](https://www.npmjs.com/package/send)

## Usage

```js
const e2k = require('express-to-koa')

// Some express middleware
const devMiddleware = require('webpack-dev-middleware')(compiler, {
  publicPath,
  quiet: true
})

const app = new Koa()
app.use(e2k(devMiddleware))
```

## What Kind of Express Middlewares are Supported?

NEARLY **ALL** express middlewares built with best practices.

**TL;NR**

`express-to-koa` does not support all arbitrary express middlewares, but only for those who only uses **Express-Independent** APIs like `res.write` and `res.end`, i.e. the APIs that node [http.ServerResponse](https://nodejs.org/dist/latest-v7.x/docs/api/http.html#http_class_http_serverresponse) provides.

However, if a middleware uses APIs like `res.send` or something, `express-to-koa` will do far too much work to convert those logic to koa2, which is not easier than creating both express and koa2 from 0 to 1.

So, it is a good practice to write framework-agnostic middlewares or libraries.

## Supported Middlewares

- [webpack-dev-middleware](https://www.npmjs.com/package/webpack-dev-middleware)
- [webpack-hot-middleware](https://www.npmjs.com/package/webpack-hot-middleware)
- [next.getRequestHandler()](https://github.com/zeit/next.js/#custom-server-and-routing)
- Other middlewares which are waiting for you to add to the README. Any contributions are welcome.

## License

MIT

---
_Source: https://npm.io/package/express-to-koa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
