Merc Merc - 7 months ago 19
Node.js Question

What is the difference between next() and next('route') in an expressjs app.VERB call?

The docs read:

The app.VERB() methods provide the routing functionality in Express,
where VERB is one of the HTTP verbs, such as Multiple
callbacks may be give, all are treated equally, and behave just like
middleware, with the one exception that these callbacks may invoke
next('route') to bypass the remaining route callback(s). This
mechanism can be used to perform pre-conditions on a route then pass
control to subsequent routes when there is no reason to proceed with
the route matched.

What do they mean by "bypass the remaining route callbacks?"? I know that
will pass control to the next matching route. But... what function will get control with


I hated it when I answer my own question 5 minutes later. next('route') is when using route middleware. So if you have:

app.get('/forum/:fid', middleware1, middleware2, function(){
  // ...

the function middleware1() has a chance to call next() to pass control to middleware2, or next('route') to pass control to the next matching route altogether.