title: What is next() in NodeJs?
body: <p>I am new to NodeJs coming from Java background, I'm trying to understand the use of the convention <strong>next()</strong> call.<br></p>
  
  <p><strong>I've gone through the following posts -</strong><br>
  1. <a href="https://stackoverflow.com/questions/5384526/javascript-node-js-next">javascript node.js next()</a><br>
  2. <a href="https://www.naeemrana.com/node-js/express-js-middleware-what-is-next/" rel="noreferrer">https://www.naeemrana.com/node-js/express-js-middleware-what-is-next/</a><br>
  3. <a href="https://stackoverflow.com/questions/16810449/when-to-use-next-and-return-next-in-node-js">When to use next() and return next() in Node.js</a><br></p>
  
  <p>What I could make of them is next() is similar to a callback or maybe a reference of the next function to be executed after the current function's execution,<br>
  Also understood it's recommended to use <code>return next();</code> instead of <code>next();</code> to avoid the function to be re-executed.</p>
  
  <p><strong>Following is a sample code from one the links -</strong><br></p>
  
  <pre><code>app.get('/users/:id', function(req, res) {
      var user_id = req.params.id;
  
      if(user_id) {
        // do something
      } else {
        next(); // here comes middleware.
      }
  });
  </code></pre>
  
  <p>What I don't understand here is the function being executed does not have the 3rd argument,<br> 
  but it does invoke the next() function, what is the idea here?<br>
  Is the use of this convention only to be used on routes logic?<br>
  Is next() a callback? is it a reference to the next function to be executed? or something else?<br></p>