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?
Yes, if an error, both will be called. You want to do:
if(err) {
return next(err);
}
Calling next()
DOES NOT HALT EXECUTION, but return
does, so return next() does return.