title: TypeError : next() is not a function
body: <p>I am writing a middleware function that looks for validation errors and if the error is found gives out a certain output else continues the program flow. I have two functions with the exact code but they check for different schemas.</p>
  <p>My first function runs without any exception. However, when I try to execute the second function I get an error in the console.</p>
  <pre><code>const validateCampground = (req, res, next) =&gt; {
    const { error } = campgroundSchema.validate(req.body);
    if (error) {
      const msg = error.details.map((el) =&gt; el.message).join(&quot;,&quot;);
      throw new ExpressError(msg, 400);
    } else {
      next();
    }
  };
  
  const validateReview = (req, res, next) =&gt; {
    const { error } = reviewSchema.validate(req.body);
    if (error) {
      const msg = error.details.map((el) =&gt; el.message).join(&quot;,&quot;);
      throw new ExpressError(msg, 400);
    } else {
      next(); //this is the point where the exception occurs
    }
  };
  </code></pre>
  <p>It is only inside the validateReview function where next middleware function is not recognised as a valid function.</p>
  <p><a href="https://i.stack.imgur.com/Cmo8E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cmo8E.png" alt="Console Error Log" /></a></p>