title: Pass parameters from router to controller in ExpressJS
body: <p>I have a route that is defined as such</p>
  
  <p><code>router.route('/:id/organisers').get(HackathonControllers.getHackathonRoles());</code></p>
  
  <p>Now, the <code>getHackathonRoles</code> is a controller defined as such for example:</p>
  
  <pre><code>function getHackathonRoles(role, req, res, next) {
      console.log(role);
      res.status(200).json({
          message: `Successfully updated Hackathon ${hackathonId}, published status updated to ${hackathonPublishedStatus}`
      })
  }
  </code></pre>
  
  <p>What I ideally want to do is pass in a role by defining multiple router endpoints. Something like:</p>
  
  <p><code>router.route('/:id/organisers').get(HackathonControllers.getHackathonRoles(role='organiser'));</code></p>
  
  <p>And</p>
  
  <p><code>router.route('/:id/volunteer').get(HackathonControllers.getHackathonRoles(role='volunteer'));</code></p>
  
  <p>So basically I want to reuse the <code>getHackathonRoles</code> method and want to avoid rewriting the same method for different roles. I ideally, I should be able <code>console.log(role)</code> in the controller. </p>
  
  <p>As of now, this fails and I get the error:</p>
  
  <blockquote>
    <p>router.route('/:id/organisers').get(_hackathonController2.default.getHackathonRoles(role
    = 'organiser'));</p>
  </blockquote>
  
  <p>How do I work around this and keep it sort of DRY? I <em>don't want to incorporate parameters</em> into the endpoint like <code>/:id/?</code> and the arguments are like <code>role=organiser</code> or <code>role=volunteer</code> etc.</p>