title: How to use express-async-handler
body: <p>I am going through some code on github: <a href="https://github.com/linnovate/mean/blob/master/server/routes/user.route.js" rel="nofollow noreferrer">https://github.com/linnovate/mean/blob/master/server/routes/user.route.js</a></p>
  
  <p>But there is a portion of it I don't understand, that is:</p>
  
  <pre><code>router.route('/')
      .post(asyncHandler(insert));
  </code></pre>
  
  <p>On npm <a href="https://www.npmjs.com/package/express-async-handler" rel="nofollow noreferrer" title="express-async-handler">express-async-handler</a>
  is described as:</p>
  
  <blockquote>
    <p>Simple middleware for handling exceptions inside of async express routes and passing them to your express error handlers.</p>
  </blockquote>
  
  <p>They go give an example of how to use the module, but it doesn't explain much.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li><p>How is the insert function on line 12 called without parentheses?</p></li>
  <li><p>What is the function of asyncHandler(), what would the code look like if you decide on not using it?</p></li>
  <li><p>Normally when using <strong><em>router.route('/').post</em></strong> there are curly braceswhich follow. In this code I cant see any. So my question are: Is the <strong><em>async function insert</em></strong> part of the function body of <strong><em>router.route('/').post</em></strong>? and if not then why are there no curly braces? </p></li>
  <li><p>What exactly is being exported here <a href="https://github.com/linnovate/mean/blob/master/server/controllers/user.controller.js" rel="nofollow noreferrer" title="user.controller.js">user.controller.js</a> on line 14 (is it an object, a var...)? What is the advantage of exporting it this way? Why not just export the function insert()?</p></li>
  </ol>
  
  <p>Thank you in advance.</p>