Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

express和koa的middleware没区别吧?

$
0
0

两者无论写法,还是执行顺序,也没啥区别啊,区别是啥???

var app = require('express')();
app.use(function myMiddleware(req, res, next) {  
  res.write('Hello world.');
  next();
});
app.use(function mySecondMiddleware(req, res) {  
  res.write('\nI am a second middleware.');
  res.end();
});

var app = require('koa')();
app.use(function* myMiddleware(next) {  
  this.response.body = 'Hello world.';
  yield next;
});

app.use(function* mySecondMiddleware() {  
  this.response.body += '\nI am a second middleware.';
});

Viewing all articles
Browse latest Browse all 14821

Trending Articles