Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

koa 核心功能样例

const Koa = require('koa');
const app = new Koa();

app.use(async (ctx, next) => {
	console.log('Middleware 1 Start');
	await next();
	console.log('Middleware 1 End');
});

app.use(async (ctx, next) => {
	console.log('Middleware 2 Start');
	await next();
	console.log('Middleware 2 End');

	ctx.body = 'hello, world';
});

app.listen(3000);

// 终端 output:
// Middleware 1 Start
// Middleware 2 Start
// Middleware 2 End
// Middleware 1 End

在 koa 官方 blog 上有个非常代表性的中间件 gif 图 1665906350298

koa 模块

测试

npm test

打开 localhost:5000

终端: 1665910099895