只是一个关于一些 Node + Express 中间件的快速问题,它在我的 Node cmd 提示符下两次输出 1 次对 console.log 的调用。它只是没有意义,想知道是否有人可以解释为什么这会发生在我身上。
server.js
var express = require('express');
var app = express();
//Outputs in my console twice?!
app.use('/', function(req, res, next) {
console.log('Request Logged by Node+Express Server Middleware @ ' + Date());
next();
});
app.get('*', function(req, res) {
res.send('Hey world.');
});
app.listen(1337);
最佳答案
我知道发生了什么,Chrome 正在向 favicon.ico 发出额外的请求,因此出现了双重输出。有道理。
关于node.js - Node Express 中间件一次调用两次输出 console.log()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32103921/