title: node express: should you always call next() in a get or post handler?
body: <p>Until now I've defined my <code>get</code> and <code>post</code> handlers with just <code>(req, res)</code> as arguments, with the assumption being that I put these handlers last in the chain of middleware, and make sure that I handle any responses and error handling properly within these handlers... hence it doesn't matter that I don't make any reference to <code>next</code>.</p>
  
  <p>Is this a valid and sensible approach, or is it good practice always to call <code>next()</code> even if (at present) there is nothing coming afterwards?  For example, perhaps in the future you might want to do some handling after these routes... or maybe there's a reason I haven't yet come across why it's good practice to always call <code>next()</code>.</p>
  
  <p>For example, there is the following simple example in the express <a href="https://expressjs.com/en/guide/routing.html" rel="noreferrer">routing guide</a>:</p>
  
  <pre><code>app.get('/example/b', function (req, res, next) {
      console.log('the response will be sent by the next function ...')
      next()
  }, function (req, res) {
      res.send('Hello from B!')
  })
  </code></pre>
  
  <p>Of course, I appreciate that this is a very simple example to illustrate that handlers can be chained, and is not intended to provide a complete framework for a <code>get</code> handler, but would it be better to define and use <code>next</code> even in the second handler, as follows?</p>
  
  <pre><code>app.get('/example/b', function (req, res, next) {
      console.log('the response will be sent by the next function ...')
      next()
  }, function (req, res, next) {
      res.send('Hello from B!')
      next()
  })
  </code></pre>
  
  <p>Or is it actually common practice to assume that a handler function that sends a response back to the client should <strong>not</strong> call <code>next()</code>... i.e. the assumption should be that the chain will end at the handler that actually sends the response?</p>
  
  <p>Or is there no established practice on this point?</p>
  
  <p>I'm even wondering whether it might be common not to send any response in the <code>get</code> handler but to defer that to a dedicated response handler coming after... by which I mean an <code>OK</code> response handler rather than an error response handler (for which it seems to be common practice to defined a <a href="https://expressjs.com/en/guide/error-handling.html" rel="noreferrer">final error handler</a> and call <code>next(err)</code>).  So, in a non-error situation, you would call <code>next()</code> and in the following middleware you would do your <code>res.status(200).send(req.mydata)</code> where <code>req.mydata</code> is added in your <code>get</code> handler.</p>