Socket
Socket
Sign inDemoInstall

koa-connect

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-connect - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

yarn.lock

4

package.json
{
"name": "koa-connect",
"version": "2.0.0",
"version": "2.0.1",
"description": "Use Connect/Express middleware in Koa",

@@ -9,3 +9,3 @@ "repository": "vkurchatkin/koa-connect",

"contributors": [
"Louis DeScioli <louis.descioli@gmail.com>"
"Louis DeScioli (https://descioli.design)"
],

@@ -12,0 +12,0 @@ "license": "MIT",

@@ -1,12 +0,18 @@

# koa-connect
# koa-connect [![npm package badge][npm badge]][npm]
Use [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with Koa.
[npm badge]: https://badge.fury.io/js/koa-connect.svg
[npm]: https://www.npmjs.com/package/koa-connect
Use [Express](https://github.com/strongloop/express)/[Connect](https://github.com/senchalabs/connect) middleware with [Koa](https://github.com/koajs/koa).
## Warning
It 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.
### Always use `next`
### Always use `next` middleware parameter
Express middlewares need to declare and invoke the `next` callback appropriately for the koa-connect integration to work correctly.
### For library authors
If 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`.

@@ -17,8 +23,9 @@

```sh
npm install koa-connect@next
npm install koa-connect
```
## Usage
See `examples/` for more real-world examples.
See [`examples/`](./examples) for more practical usage.
```javascript

@@ -29,4 +36,4 @@ const Koa = require('koa')

// A generic Express-style middleware function
function connectMiddlware (req, res, next) {
res.writeHead(200, {'Content-Type': 'text/plain'})
function connectMiddlware(req, res, next) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('From the Connect middleware')

@@ -36,3 +43,3 @@ next()

// A generic Koa v2 middlware, without async/await
// A generic Koa middlware, without async/await
function koaMiddlware(ctx, next) {

@@ -43,3 +50,3 @@ next()

})
.catch((err) => {
.catch(err => {
// Error handling from downstream middleware, like usual

@@ -49,6 +56,6 @@ })

// A generic Koa v2 middlware with async/await
// A generic Koa middlware with async/await
async function koaMiddleware(ctx, next) {
try {
await next();
await next()
} catch (e) {

@@ -71,5 +78,7 @@ // Normal error handling

## Testing
Tests are in `tests.js` and are made with the [Mocha](https://mochajs.org) framework. You can run them with `npm test` or `npm run test:watch`
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc