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
npm install koa2
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
894,119
Last Day
7
Last Week
103
Last Month
430
Last Year
19,939
35,296 Stars
1,220 Commits
3,225 Forks
832 Watching
8 Branches
246 Contributors
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
Publised On
17 Sept 2016
Cumulative downloads
Total Downloads
Last day
-12.5%
7
Compared to previous day
Last week
-12.7%
103
Compared to previous week
Last month
-92.4%
430
Compared to previous month
Last year
-40.7%
19,939
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
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
6 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 9
Reason
2 existing vulnerabilities detected
Details
Reason
Found 17/27 approved changesets -- score normalized to 6
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
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 2024-12-30
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