内容简介:Tkoa是使用 typescript 编写的 koa 框架! 尽管它是基于 typescript 编写,但是你依然还是可以使用一些 node.js 框架和基于 koa 的中间件。 不仅如此,你还可以享受 typescript 的类型检查系统和方便地使用 type...
Tkoa是使用 typescript 编写的 koa 框架!
尽管它是基于 typescript 编写,但是你依然还是可以使用一些 node.js 框架和基于 koa 的中间件。
不仅如此,你还可以享受 typescript 的类型检查系统和方便地使用 typescript 进行测试!
安装
TKoa 需要 >= typescript v3.1.0 和 node v7.6.0 版本。
$ npm install tkoa
Hello T-koa
import tKoa = require('tkoa');
interface ctx {
res: {
end: Function
}
}
const app = new tKoa();
// response
app.use((ctx: ctx) => {
ctx.res.end('Hello T-koa!');
});
app.listen(3000);
Middleware
Tkoa 是一个中间件框架,拥有两种中间件:
- 异步中间件
- 普通中间件
下面是一个日志记录中间件示例,其中使用了不同的中间件类型:
async functions (node v7.6+):
interface ctx {
method: string,
url: string
}
app.use(async (ctx: ctx, next: Function) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
Common function
// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,
// 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.
interface ctx {
method: string,
url: string
}
app.use((ctx: ctx, next: Function) => {
const start = Date.now();
return next().then(() => {
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
});
Getting started
Support
TypeScript
- 大于等于 v3.1 版本
Node.js
- 大于等于 v7.6.0 版本
License
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- One 框架 2.0.13 发布
- Total.js 框架 v2.6.0 发布,Node.js 的 MVC 框架
- Total.js 框架 v2.6.0 发布,Node.js 的 MVC 框架
- 快嘉框架 v1.6 更新发布,J2EE 开发框架实例
- 快嘉框架 v2.0 更新发布,J2EE 开发框架实例
- 快嘉框架 v2.0 更新发布,J2EE 开发框架实例
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数据挖掘导论
Pang-Ning Tan、Michael Steinbach、Vipin Kumar / 范明、范宏建 / 人民邮电出版社 / 2010-12-10 / 69.00元
本书全面介绍了数据挖掘,涵盖了五个主题:数据、分类、关联分析、聚类和异常检测。除异常检测外,每个主题都有两章。前一章涵盖基本概念、代表性算法和评估技术,而后一章讨论高级概念和算法。这样读者在透彻地理解数据挖掘的基础的同时,还能够了解更多重要的高级主题。 本书是明尼苏达大学和密歇根州立大学数据挖掘课程的教材,由于独具特色,正式出版之前就已经被斯坦福大学、得克萨斯大学奥斯汀分校等众多名校采用。 ......一起来看看 《数据挖掘导论》 这本书的介绍吧!
