TypeError: req.next is not a function

Viewed 15489

Getting this error in node, I think it's due to something to do with one of my pieces of middleware, but the line of code that it points to is my user controller at a res.render() call.

I can't find anyone writing about this error online and couldn't figure out the cause after looking at the code for a while. Any ideas?

enter image description here

2 Answers

In my case, I need to return the next()

// Error
    app.use((req, res, next) => {
      if(!req.session.userId) {
        next(); // <<<<< Error
      } 
    })

// Solution
    app.use((req, res, next) => {
      if(!req.session.userId) {
        return next();
      } 
    })
Related