本文介绍了Node Express Middleware一次调用两次输出console.log()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于一些Node + Express中间件的快速问题,该中间件在我的节点cmd提示符下两次向console.log输出1个调用.只是没有意义,并且想知道是否有人可以解释为什么这会发生在我身上.
just a quick question about some Node + Express middleware that is outputting 1 call to console.log twice in my node cmd prompt. It just doesn't make sense and was wondering if someone could explain why this is occurring for me.
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发出附加请求,因此输出翻倍.有道理.
I figured out what was going on, Chrome was making an additional request to favicon.ico, thus the double outputs. Makes sense.
这篇关于Node Express Middleware一次调用两次输出console.log()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!