{"name":"koa-connect","version":"2.0.0","description":"Use Connect/Express middleware in Koa","repository":{"type":"git","url":"git+https://github.com/vkurchatkin/koa-connect.git"},"main":"index.js","author":{"name":"Vladimir Kurchatkin","email":"vladimir.kurchatkin@gmail.com"},"contributors":[{"name":"Louis DeScioli","email":"louis.descioli@gmail.com"}],"license":"MIT","scripts":{"test":"mocha tests.js","test:watch":"npm run test -- --watch --reporter nyan"},"devDependencies":{"koa":"^2.0.0","mocha":"^2.3.4","supertest":"^1.1.0"},"keywords":["koa","connect","express","middleware"],"gitHead":"43e59d484a311fa3ecb4dce5f4c8edf487ecd5f9","bugs":{"url":"https://github.com/vkurchatkin/koa-connect/issues"},"homepage":"https://github.com/vkurchatkin/koa-connect#readme","_id":"koa-connect@2.0.0","_shasum":"b69da158fe5df04a59f5fce57b147343f6ff652e","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"lourd","email":"louis@grovelabs.io"},"dist":{"shasum":"b69da158fe5df04a59f5fce57b147343f6ff652e","tarball":"http://registry-npm.ywwl.com/koa-connect/download/koa-connect-2.0.0.tgz","integrity":"sha512-QO0hw6zwBdQ7LCs+IOor/R6RSR+Q2TtRhosJV7vCvfNmLtr19z8ysmAGpre6TkdcWF4p6ksIBky7wwVsBjxYTA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAx3IJezvsRL/jqzJS7Lmp/26JECmLFb6tUibJWdWpMPAiBO9IZwu/nDreyxxMpxeKZDi7hKoa/FxUcbLnXfKyoD9w=="}],"size":3370,"noattachment":false,"key":"/koa-connect/-/koa-connect-2.0.0.tgz"},"maintainers":[{"name":"lourd","email":"louis@grovelabs.io"},{"name":"vkurchatkin","email":"vladimir.kurchatkin@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/koa-connect-2.0.0.tgz_1484238134410_0.5455546798184514"},"directories":{},"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":1484238136334,"_cnpm_publish_time":1484238136334,"dist-tags":{"latest":"2.1.1"}}