Just wanted to get this out of my head:
when dealing with routing in Express/ Nodejs I want to know if calling next() always returns the function it is called from? Consider:
app.get('/users/:id?', function(req, res, next){
//just as as example
var err = doValidation(req);
if (err) {
next(err);
}
next(); //will this ever be called?
});
In case of an error, will the second next() ever be called, or will a call for the first next(err) (automagically) return the function it is called from?
Calling next() doesn't halt execution, but return does, so return next() does return.
Yes, if an error, both will be called. You want to do:
if(err) {
return next(err);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With