Gathering detailed insights and metrics for koa2
Gathering detailed insights and metrics for koa2
Gathering detailed insights and metrics for koa2
Gathering detailed insights and metrics for koa2
Expressive middleware for node.js using ES2017 async functions
npm install koa2
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.8
Supply Chain
95.5
Quality
72.4
Maintenance
50
Vulnerability
100
License
JavaScript (100%)
Total Downloads
897,498
Last Day
15
Last Week
142
Last Month
604
Last Year
14,994
MIT License
35,549 Stars
1,261 Commits
3,225 Forks
821 Watchers
8 Branches
249 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
2.0.0-alpha.7
Package Id
koa2@2.0.0-alpha.7
Size
14.48 kB
NPM Version
3.10.6
Node Version
4.4.7
Published on
Sep 17, 2016
Cumulative downloads
Total Downloads
Last Day
114.3%
15
Compared to previous day
Last Week
2.2%
142
Compared to previous week
Last Month
-24.3%
604
Compared to previous month
Last Year
-33.2%
14,994
Compared to previous year
24
Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.
Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~570 SLOC codebase. This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.
Koa is not bundled with any middleware.
Koa requires node v4.0.0 or higher for (partial) ES2015 support.
$ npm install koa@next
1const Koa = require('koa'); 2const app = new Koa(); 3 4// response 5app.use(ctx => { 6 ctx.body = 'Hello Koa'; 7}); 8 9app.listen(3000);
Koa is a middleware framework that can take 3 different kinds of functions as middleware:
Here is an example of logger middleware with each of the different functions:
1// Middleware normally takes two parameters (ctx, next), ctx is the context for one request, 2// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion. 3 4app.use((ctx, next) => { 5 const start = new Date(); 6 return next().then(() => { 7 const ms = new Date() - start; 8 console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); 9 }); 10});
1app.use(async (ctx, next) => { 2 const start = new Date(); 3 await next(); 4 const ms = new Date() - start; 5 console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); 6});
To use generator functions, you must use a wrapper such as co that is no longer supplied with Koa.
1app.use(co.wrap(function *(ctx, next) { 2 const start = new Date(); 3 yield next(); 4 const ms = new Date() - start; 5 console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); 6}));
Old signature middleware (v1.x) support will be removed in v3
Koa v2.x will try to convert legacy signature, generator middleware on app.use
, using koa-convert.
It is however recommended that you choose to migrate all v1.x middleware as soon as possible.
1// Koa will convert 2app.use(function *(next) { 3 const start = new Date(); 4 yield next; 5 const ms = new Date() - start; 6 console.log(`${this.method} ${this.url} - ${ms}ms`); 7});
You could do it manually as well, in which case Koa will not convert.
1const convert = require('koa-convert'); 2 3app.use(convert(function *(next) { 4 const start = new Date(); 5 yield next; 6 const ms = new Date() - start; 7 console.log(`${this.method} ${this.url} - ${ms}ms`); 8}));
For Node 4.0 and Babel 6.0 you can setup like this:
1$ npm install babel-register babel-plugin-transform-async-to-generator --save
1// set babel in entry file 2require('babel-register')({ 3 plugins: ['transform-async-to-generator'] 4});
Check out an example in koa's test.
$ make test
See AUTHORS.
MIT
No vulnerabilities found.
Reason
21 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 7/24 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More