From bbfa6777a09e1c79045f13e45f76fe4c29109bb8 Mon Sep 17 00:00:00 2001 From: Jonathan Ong Date: Sun, 17 Jan 2016 16:27:23 -0800 Subject: [PATCH] readme: add docs about v2. closes #603 --- Readme.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 080ea19..aeb705f 100644 --- a/Readme.md +++ b/Readme.md @@ -18,10 +18,30 @@ $ npm install koa ``` - Koa is supported in all versions of [iojs](https://iojs.org) without any flags. + Koa is supported in node v4+ and node v0.12 with the `--harmony-generators` or `--harmony` flag. - To use Koa with node, you must be running __node 0.12.0__ or higher for generator and promise support, and must run node(1) - with the `--harmony-generators` or `--harmony` flag. +## v2 Alpha + + Koa v2 is currently in alpha. In this new version, the middleware function signature completely changes in favor of ES6 syntax: + +```js +// uses async arrow functions +app.use(async (ctx, next) => { + try { + await next() // next is now a function + } catch (err) { + ctx.body = { message: err.message } + ctx.status = err.status || 500 + } +}) + +app.use(async ctx => { + const user = await User.getById(this.session.userid) // await instead of yield + ctx.body = user // ctx instead of this +}) +``` + To learn more about Koa v2, follow this issue: https://github.com/koajs/koa/issues/533. + To try Koa v2, `npm install koa@2.0.0-alpha.3`. ## Community