koa
Koa web app framework
Last updated 5 years ago by dead_horse .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install koa 
SYNC missed versions from official npm registry.
koa middleware framework for nodejs

gitter NPM version build status Test coverage OpenCollective Backers OpenCollective Sponsors

Expressive, light-weight HTTP framework for node.js to make web applications and APIs more enjoyable to write. Koa requests flow through middleware in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream. Koa's use of generators also greatly increases the readability and robustness of your application.

Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~550 SLOC codebase. This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.

Koa is not bundled with any middleware, but there is a large collection of community middleware to choose from.

Installation

$ npm install koa

Koa is supported in node v4+ and node v0.12 with the --harmony-generators or --harmony flag.

Koa v2

Koa v2 is currently released with the next tag (meaning it will not be marked as latest). You can install it with semver:

npm install koa@next

In this new version, the middleware function signature changes to adopt async/await:

// Koa application is now a class and requires the new operator.
const app = new Koa();

// 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(ctx.session.userid); // await instead of yield
  ctx.body = user; // ctx instead of this
});

Until async/await is natively supported in Node Koa 1.x is the official release, however you may wish to adopt 2.x early by using Babel to compile. Koa 1.x generator-based middleware may be "upgraded" to the 2.x flavour using koa-convert.

To learn more about Koa v2, follow this issue or read the docs here: https://github.com/koajs/koa/tree/v2.x/docs.

Community

Getting started

  • Kick-Off-Koa - An intro to koa via a set of self-guided workshops.
  • Workshop - A workshop to learn the basics of koa, Express' spiritual successor.
  • Introduction Screencast - An introduction to installing and getting started with Koa

Example

var koa = require('koa');
var app = koa();

// logger

app.use(function *(next){
  var start = new Date;
  yield next;
  var ms = new Date - start;
  console.log('%s %s - %s', this.method, this.url, ms);
});

// response

app.use(function *(){
  this.body = 'Hello World';
});

app.listen(3000);

Running tests

$ make test

Authors

Backers

Support us with a monthly donation and help us continue our activities.

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.

License

MIT

Current Tags

  • 3.0.0-alpha.2                                ...           experimental (11 days ago)
  • 2.15.3                                ...           latest (7 months ago)
  • 0.21.1                                ...           latest-0 (6 years ago)
  • 2.15.3                                ...           next (7 months ago)
  • 1.7.0                                ...           v1 (5 years ago)

105 Versions

  • 3.0.0-alpha.2                                ...           11 days ago
  • 2.15.3                                ...           7 months ago
  • 2.15.2                                ...           8 months ago
  • 2.15.1                                ...           8 months ago
  • 2.15.0                                ...           a year ago
  • 3.0.0-alpha.1                                ...           2 years ago
  • 2.14.2                                ...           2 years ago
  • 3.0.0-alpha.0                                ...           2 years ago
  • 2.14.1                                ...           2 years ago
  • 2.14.0                                ...           2 years ago
  • 2.13.4                                ...           3 years ago
  • 2.13.3                                ...           3 years ago
  • 2.13.2                                ...           3 years ago
  • 2.13.1                                ...           4 years ago
  • 2.13.0                                ...           4 years ago
  • 2.12.1                                ...           4 years ago
  • 2.12.0                                ...           4 years ago
  • 2.11.0                                ...           5 years ago
  • 1.7.0                                ...           5 years ago
  • 2.10.0                                ...           5 years ago
  • 2.9.0                                ...           5 years ago
  • 2.8.2                                ...           5 years ago
  • 2.8.1                                ...           5 years ago
  • 2.8.0                                ...           5 years ago
  • 2.7.0                                ...           6 years ago
  • 2.6.2                                ...           6 years ago
  • 2.6.1                                ...           6 years ago
  • 2.6.0                                ...           6 years ago
  • 0.21.1                                ...           6 years ago
  • 2.5.3                                ...           6 years ago
  • 1.6.2                                ...           6 years ago
  • 1.6.1                                ...           6 years ago
  • 2.5.2                                ...           6 years ago
  • 2.5.1                                ...           7 years ago
  • 1.6.0                                ...           7 years ago
  • 2.5.0                                ...           7 years ago
  • 1.5.1                                ...           7 years ago
  • 1.5.0                                ...           7 years ago
  • 2.4.1                                ...           7 years ago
  • 1.4.1                                ...           7 years ago
  • 2.3.0                                ...           7 years ago
  • 1.4.0                                ...           8 years ago
  • 2.2.0                                ...           8 years ago
  • 1.3.0                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0-alpha.8                                ...           8 years ago
  • 1.2.5                                ...           8 years ago
  • 2.0.0-alpha.7                                ...           8 years ago
  • 1.2.4                                ...           8 years ago
  • 1.2.3                                ...           8 years ago
  • 1.2.2                                ...           8 years ago
  • 2.0.0-alpha.6                                ...           8 years ago
  • 2.0.0-alpha.5                                ...           8 years ago
  • 2.0.0-alpha.4                                ...           8 years ago
  • 1.2.1                                ...           8 years ago
  • 2.0.0                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.2                                ...           9 years ago
  • 2.0.0-alpha.3                                ...           9 years ago
  • 2.0.0-alpha.2                                ...           9 years ago
  • 1.1.1                                ...           9 years ago
  • 2.0.0-alpha.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.21.0                                ...           9 years ago
  • 0.20.0                                ...           10 years ago
  • 0.19.1                                ...           10 years ago
  • 0.19.0                                ...           10 years ago
  • 0.18.1                                ...           10 years ago
  • 0.18.0                                ...           10 years ago
  • 0.17.0                                ...           10 years ago
  • 0.16.0                                ...           10 years ago
  • 0.15.0                                ...           10 years ago
  • 0.14.0                                ...           10 years ago
  • 0.13.0                                ...           10 years ago
  • 0.12.2                                ...           10 years ago
  • 0.12.1                                ...           10 years ago
  • 0.12.0                                ...           10 years ago
  • 0.11.0                                ...           10 years ago
  • 0.10.0                                ...           10 years ago
  • 0.9.0                                ...           10 years ago
  • 0.8.2                                ...           10 years ago
  • 0.8.1                                ...           10 years ago
  • 0.8.0                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.3                                ...           10 years ago
  • 0.6.2                                ...           10 years ago
  • 0.6.1                                ...           11 years ago
  • 0.6.0                                ...           11 years ago
  • 0.5.5                                ...           11 years ago
  • 0.5.4                                ...           11 years ago
  • 0.5.3                                ...           11 years ago
  • 0.5.2                                ...           11 years ago
  • 0.5.1                                ...           11 years ago
  • 0.5.0                                ...           11 years ago
  • 0.4.0                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Downloads
Total 18
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (23)
Dev Dependencies (8)

© 2010 - cnpmjs.org x YWFE | Home | YWFE