Skip to content

Commit

Permalink
docs++
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Feb 25, 2017
1 parent f191c0d commit d4b3223
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
29 changes: 15 additions & 14 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
Koa is not bundled with any middleware.

## Installation
Koa requires __node v4.0.0__ or higher for (partial) ES2015 support.

Koa requires __node v7.6.0__ or higher for ES2015 and async function support.

```
$ npm install koa@next
$ npm install koa
```

## Hello koa
Expand Down Expand Up @@ -49,6 +50,17 @@ Koa is a middleware framework that can take 3 different kinds of functions as mi

Here is an example of logger middleware with each of the different functions:

### ___async___ functions (node v7.6+)

```js
app.use(async (ctx, next) => {
const start = new Date();
await next();
const ms = new Date() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
```

### Common function

```js
Expand All @@ -64,17 +76,6 @@ app.use((ctx, next) => {
});
```

### ___async___ functions (Babel required)

```js
app.use(async (ctx, next) => {
const start = new Date();
await next();
const ms = new Date() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
```

### GeneratorFunction

To use generator functions, you must use a wrapper such as [co](https://github.com/tj/co) that is no longer supplied with Koa.
Expand Down Expand Up @@ -120,7 +121,7 @@ app.use(convert(function *(next) {

## Babel setup

For Node 4.0 and Babel 6.0 you can setup like this:
For Node 4.0+ and Babel 6.0 you can setup like this:

```bash
$ npm install babel-register babel-plugin-transform-async-to-generator --save
Expand Down
8 changes: 4 additions & 4 deletions docs/api/index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Installation

Koa requires __node v4.0.0__ or higher for (partial) ES2015 support.
Koa requires __node v7.6.0__ or higher for ES2015 and async function support.

You can quickly install a supposed version of node with your favorite version manager:

```bash
$ nvm install v4.0.0
$ nvm install 7
$ npm i koa
$ node my-koa-app.js
```

## Async Functions with Babel

To use `async` functions in Koa, we recommend using [babel's require hook](http://babeljs.io/docs/usage/require/).
To use `async` functions in Koa in versions of node < 7.6, we recommend using [babel's require hook](http://babeljs.io/docs/usage/require/).

```js
require('babel-core/register');
Expand Down Expand Up @@ -183,7 +183,7 @@ ctx.cookies.set('name', 'tobi', { signed: true });

## app.context

`app.context` is the prototype from which `ctx` is created from.
`app.context` is the prototype from which `ctx` is created from.
You may add additional properties to `ctx` by editing `app.context`.
This is useful for adding properties or methods to `ctx` to be used across your entire app,
which may be more performant (no middleware) and/or easier (fewer `require()`s)
Expand Down

0 comments on commit d4b3223

Please sign in to comment.