Registry / web-framework / koa2-connect

koa2-connect

JSON →
library1.0.2jsnpmunverified

A small utility (v1.0.2, last updated 2019) that adapts Connect/Express-style middleware (req, res, next) to work with Koa 2.x async middleware (ctx, next). Unlike koa-connect, koa2-connect is designed to better support streaming middleware like webpack-dev-middleware and webpack-hot-middleware. It is a stopgap for when Koa-native alternatives are unavailable; not recommended for new projects where Koa-native middleware exists.

npm install koa2-connect
INSTALL
IMPORT
SIG · KOA2-CONNECT
K
koa2-connect
web-frameworkjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

c2k
const c2k = require('koa2-connect')
import c2k from 'koa2-connect'
No default ESM export; use CommonJS require or synthetic default import.
default
const conv = require('koa2-connect')
import { convert } from 'koa2-connect'
The module exports a single function; named imports like convert are incorrect.
Promise
const c2k = require('koa2-connect'); app.use(c2k(someExpressMiddleware))
app.use(someExpressMiddleware)
Directly using Express middleware without wrapping will break because Koa expects a different signature.

Wrap an Express-style middleware with c2k and use it in a Koa app.

const Koa = require('koa'); const c2k = require('koa2-connect'); const app = new Koa(); // Express-style middleware function expressMiddleware(req, res, next) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello from Express'); next(); } app.use(c2k(expressMiddleware)); app.use((ctx) => { ctx.body = 'Koa response'; }); app.listen(3000);
Debug
Known issues
gotchaExpress middleware must call next() to allow Koa middleware downstream to execute.
fix
Ensure your Express middleware invokes next() when done, or use a Koa-native alternative.
affects: >=1.0
gotchaThe module does not provide types; you may need to add your own type declarations.
fix
Install @types/koa2-connect if available, or declare module 'koa2-connect' { ... }.
affects: >=1.0
deprecatedPackage is in maintenance mode with no updates since 2019. Known issues may not be fixed.
fix
Consider migrating to native Koa middleware or using koa-connect as an alternative.
affects: >=1.0
gotchaExpress middleware that relies on synchronous response methods (e.g., res.sendStatus) may not trigger Koa's error handling correctly.
fix
Use a Koa-native error handler or wrap errors manually using try/catch inside the Express middleware.
affects: >=1.0
Errors
Common errors & fixes
Error: next is not a function
Your Express middleware expects a next callback, but koa2-connect may not pass one in certain failure cases.
fix
Ensure the middleware is compatible with Connect/Express and always calls next().
TypeError: Cannot read property 'status' of undefined
The Express middleware tried to access res.status, but Koa's response object has a different API.
fix
Use only raw Node.js http methods (res.writeHead, res.end) and avoid Express-specific functions like res.status.
ReferenceError: require is not defined
You are using ESM (ES modules) and need to use import instead of require.
fix
Use dynamic import: const c2k = (await import('koa2-connect')).default;
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
koa2-connect — npm install koa2-connect · libregistry