app.get - is there any difference between res.send vs return res.send

后端 未结 3 462
误落风尘
误落风尘 2020-12-25 09:42

I am new to node and express. I have seen app.get and app.post examples using both \"res.send\" and \"return res.send\". Are these the same?

var express = r         


        
3条回答
  •  有刺的猬
    2020-12-25 10:30

    app.get('/', function(req, res) {
        res.type('text/plain');
        if (someTruthyConditinal) {
            return res.send(':)');
        }
        // The execution will never get here
        console.log('Some error might be happening :(');
    });
    
    app.get('/', function(req, res) {
        res.type('text/plain');
        if (someTruthyConditinal) {
            res.send(':)');
        }
        // The execution will get here
        console.log('Some error might be happening :(');
    });
    

提交回复
热议问题