注意不显示的console.log消息:我是很新的表达express.js路由时
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('id: ' + req.params.id + ' and name: ' + req.params.name);
});
var things = require('./things/things.js');
//both index.js and things.js should be in same directory
app.use('/things', things);
//Simple request time logger
app.use('/',function(req, res, next){
console.log("A new request received at " + Date.now());
//This function call is very important. It tells that more processing is
//required for the current request and is in the next middleware
//function/route handler.
next();
});
app.listen(3000);
我正在学习有关中间件功能,我试图表现出的console.log消息,当我去到localhost :3000,但没有任何东西显示在我的控制台中,我在这里错过了什么?
啊,我不知道它会在终端,而不是浏览器控制台显示出来,这是为什么? – Snorlax
Express运行在您的服务器上运行的node.js中,而不是在用户浏览器上运行。在你的情况下,服务器只是你的电脑,但它仍然适用。 – harshpatel991