In the docs sometimes just calling next(); is enough, and sometimes middleware/path handlers use return next();.
What is the difference between both? When one should be used vs the other?
Also, it says that next('somepath'); does a redirect, and in some places there is next(false); for - I think - signaling error? And sometimes it's next(someObj); - is this for errors too?
Returning next is a control flow concept. When you need to ensure nothing else gets run in your middleware you should return next when calling it, otherwise if it's at the end of your function it doesn't matter too much.
As far as the inconsistencies with passing data to next we are going to address that soon to reduce the confusion.
next() currently has four behaviors:
next(false) - stops processing handler chain immediately, regardless of whether or not response has been flushed. next(err) - by default, will serialize the error, send it as a response AND stop processing the handler chainnext() - continue to next handler in the chainnext('redirect') - jump to another handler chainRelated: #1019
Most helpful comment
next()currently has four behaviors:next(false)- stops processing handler chain immediately, regardless of whether or not response has been flushed.next(err)- by default, will serialize the error, send it as a response AND stop processing the handler chainnext()- continue to next handler in the chainnext('redirect')- jump to another handler chain