node.js - Node Express 中间件一次调用两次输出 console.log()?

标签 node.js express

只是一个关于一些 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/

相关文章:

node.js - 删除除用户写入的文本之外的所有内容

node.js - GraphQL-突变响应后的自定义错误消息

javascript - 基于流程的编程 js html ui

node.js - Node js Express 已安装,但仍然抛出未找到错误

node.js - 如何使用和尚连接到 mongodb?

node.js - 如何使用 SessionID 从 RedisStore (connect-redis) 获取 session 数据?

javascript - Node.js/AngularJS : Shrink image files to specific file size

node.js - 如何卸载无服务器? "npm uninstall -g serverless"不工作

html - 使用 Node.js 和 HTML 网站模板提供 HTML

node.js - 尝试让 Node Express 应用程序运行