{"name":"koa-connect","version":"2.1.1","description":"Use Connect/Express middleware in Koa","repository":{"type":"git","url":"git+https://github.com/vkurchatkin/koa-connect.git"},"main":"index.js","types":"index.d.ts","author":{"name":"Vladimir Kurchatkin","email":"vladimir.kurchatkin@gmail.com"},"contributors":[{"name":"Louis DeScioli","url":"https://descioli.design"}],"license":"MIT","scripts":{"start":"tsc --watch","build":"tsc -p tsconfig-build.json","test":"mocha -r ts-node/register tests.ts","test:watch":"npm run test -- --watch --watch-extensions ts --reporter nyan"},"devDependencies":{"@types/body-parser":"^1.19.0","@types/koa":"^2.0.46","@types/mocha":"^7.0.2","@types/node":"^10.9.2","@types/supertest":"^2.0.9","body-parser":"^1.19.0","husky":"^4.2.5","koa":"^2.0.0","lint-staged":"^10.2.9","mocha":"^2.3.4","prettier":"^2.0.5","supertest":"^1.1.0","ts-node":"^8.10.2","typescript":"^3.0.1"},"keywords":["koa","connect","express","middleware"],"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"!(*.d).ts":"prettier --single-quote --write","*.md":"prettier --write"},"gitHead":"fc06368f954dfcff64de9e03776a8fa6d0d33cf5","_id":"koa-connect@2.1.1","bugs":{"url":"https://github.com/vkurchatkin/koa-connect/issues"},"homepage":"https://github.com/vkurchatkin/koa-connect#readme","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-ejvbGKYS6di4LUSS+6E+Z5ZVev9RqThLm3NfZjb9QHZMASLvnr4eDTImKcGlQXFrtVpMTyTovZ+Hcl6JbBuFNA==","shasum":"1e7c7a32e7b689dd4da6617ed5112ee259b0ced4","tarball":"http://registry-npm.ywwl.com/koa-connect/download/koa-connect-2.1.1.tgz","fileCount":14,"unpackedSize":10556,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCeRilqA6P7d1GzZs1ltHVKO4k2byOLtk1NgjAuqJ8N5AIgY5PXldGphIwKKTG3I217hBBTRFlgcQ2mQ0MBF8twt6s="}],"size":4037,"noattachment":false,"key":"/koa-connect/-/koa-connect-2.1.1.tgz"},"_npmUser":{"name":"lourd","email":"louis.descioli@gmail.com"},"directories":{},"maintainers":[{"name":"lourd","email":"louis.descioli@gmail.com"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/koa-connect_2.1.1_1770731223075_0.33210896887920716"},"_hasShrinkwrap":false,"readme":"# koa-connect [![npm package badge][npm badge]][npm]\n\n[npm badge]: https://badge.fury.io/js/koa-connect.svg\n[npm]: https://www.npmjs.com/package/koa-connect\n\nUse [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with [Koa](https://github.com/koajs/koa).\n\n## Warning\n\nIt is **highly** recommended to use a Koa-specific middleware instead of trying to convert an Express version when they're available. There is a non-trivial difference in the Koa and Express designs and you will inevitably run into some issues. This module is a workaround for the specific cases where the differences can be ignored. Additionally, it also enables library authors to write 1 version of their HTTP middleware.\n\n### Always use `next` middleware parameter\n\nExpress middlewares need to declare and invoke the `next` callback appropriately for the koa-connect integration to work correctly.\n\n### For library authors\n\nIf you're attempting to write a framework-agnostic middleware library, be sure to use only core HTTP methods and not any Express-dependent APIs like `res.send`.\n\n## Installation\n\n```sh\nnpm install koa-connect\n```\n\n## Usage\n\nSee [`examples/`](./examples) for more practical usage.\n\n```javascript\nconst Koa = require('koa');\nconst c2k = require('koa-connect');\n\n// A generic Express-style middleware function\nfunction connectMiddlware(req, res, next) {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('From the Connect middleware');\n  next();\n}\n\n// A generic Koa middlware, without async/await\nfunction koaMiddlware(ctx, next) {\n  next()\n    .then(() => {\n      // The control flow will bubble back to here, like usual\n    })\n    .catch((err) => {\n      // Error handling from downstream middleware, like usual\n    });\n}\n\n// A generic Koa middlware with async/await\nasync function koaMiddleware(ctx, next) {\n  try {\n    await next();\n  } catch (e) {\n    // Normal error handling\n  }\n  // Normal control flow\n}\n\nconst app = new Koa();\napp.use(koaMiddlware);\napp.use(c2k(connectMiddlware));\napp.use((ctx, next) => {\n  console.log('It will continue on to here');\n});\n\napp.listen(3000);\n```\n\n## Contributing\n\n### Developing\n\n`npm start` starts the TypeScript compiler in watch mode. Code will be auto-formatted upon commit as part of the Prettier + lint-staged + Husky setup.\n\n### Building\n\n`npm run build` produces the types declaration file and JavaScript file for publishing.\n\n### Testing\n\n`npm test` runs the tests. Tests are in `tests.js` and are made with the [Mocha](https://mochajs.org) framework.\n\nUse `npm run test:watch` in conjunction with `npm start` to automatically re-run the tests when the source changes.\n\n## License\n\nMIT\n","publish_time":1770731223470,"_cnpm_publish_time":1770731223470,"dist-tags":{"latest":"2.1.1"}}