什么是结束路线

时间:2014-06-04 13:30:06

标签: node.js express

我有这个路线代码:

app.get('/', function(req, res) {
    res.send('Hello world!');
});

app.get('/something', function(req, res) {
   // Do something
});

如果我在浏览器中访问/ route,将显示“Hello world”消息,我的响应将结束。

问题:此路由器中是否缺少next(),或者结束http请求的res.send()?

2 个答案:

答案 0 :(得分:2)

res.end()实际上已经结束了回复,但是res.send()会调用此回复。

您可以在来源here中看到此内容。

答案 1 :(得分:0)

抱歉,如果你想记录每个请求,包括' /'然后你必须使用:

重新排序
app.use(function(req, res, next) {

    // log each request to the console
    console.log(req.method, req.url);

    // continue doing what we were doing and go to the route
    next();
});

app.get('/', function(req, res) {
    res.send('Hello world!');
});