nodejs 里面的next()这个函数调用的作用是什么呢?
var express = require('express'); var app = express(); var myLogger = function(req, res, next){ console.log("Logger--"); next(); } app.use(myLogger); app.get('/', function(req, res, next){ // console.log(req); console.log('/'); var buffer = new Buffer(6); buffer.fill('春天'); console.log(buffer.toString()); next(); res.send({msg: 'hello,world!'}); }, function(req, res, next){ console.log('next'); next(); }, function(){ console.log('next 2'); }) app.get('/user', function(req, res){ console.log('/user'); res.send('/user'); }); var server = app.listen(8081, '0.0.0.0', function(){ var host = server.address().address; var port = server.address().port; console.log('http://%s:%s', host, port); });
参考: https://stackoverflow.com/questions/5384526/javascript-node-js-next