注意不顯示的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