1

I am using middleware to invoke the next route but for some reason it is not getting called. Here is the code:

app.get('/foo',function(req,res,next){

  console.log('first route')
  next('route')

},function(req,res,next){

  // this route is never fired 
  console.log('second route')
  res.send('second route')

})

The second function is not getting called. Any ideas

2 Answers 2

4

In the first middleware function, you're calling next with the parameter 'route'. As stated in the documentation, this causes the subsequent callbacks to be bypassed:

You can provide multiple callback functions that behave just like middleware, except that these callbacks can invoke next('route') to bypass the remaining route callback(s).

Sign up to request clarification or add additional context in comments.

Comments

0

Please change your code to

app.get('/foo',function(req,res,next){

  console.log('first route')
  return next();

},function(req,res,next){

  // this route is never fired 
  console.log('second route')
  res.send('second route')

})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.