title: node.js/JavaScript syntax - add extra parameter to passed parameters
body: <p>I'm building a REST API using node.js/Express.</p>
  
  <p>I have some middleware applied to certain routes. I have a JavaScript syntax error which I can't resolve.</p>
  
  <p><code>server.js</code></p>
  
  <pre><code>const express = require('express')
  const router = express.Router()
  
  
  const watchdogController = {
    ping: function(req, res, next) {
      console.log('watchdog')
      res.status(200).send('woof!')
      //next()
    }
  }
  const middleware = function(req, res, next) {
    console.log('middleware')
    next()
  }
  const middleware2 = function(req, res, next, roles) {
    console.log('middleware2')
    //console.log(roles)   //I want to be able to view the roles here!
    next()
  }
  
  
  //This line is where I have the issue...
  router.get('/watchdog', middleware, middleware2, watchdogController.ping)
  
  
  
  module.exports = router
  </code></pre>
  
  <p>I need to be able to pass an array of roles to <code>middleware2</code>. E.g. </p>
  
  <p><code>router.get('/watchdog', middleware, middleware2(...['ordinary','supervisor']), watchdogController.ping)</code></p>
  
  <p>But this syntax fails :( </p>
  
  <p><code>node server.js</code> results in:</p>
  
  <pre><code>middleware2
  undefined
  /Users/asdf7/Desktop/asdf7/lib/router.js:19
    next()
    ^
  
  TypeError: next is not a function
      at middleware2 (/Users/asdf7/Desktop/eoh/lib/router.js:19:3)
      at Object.&lt;anonymous&gt; (/Users/asdf7/Desktop/eoh/lib/router.js:26:37)
      at Module._compile (internal/modules/cjs/loader.js:701:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
      at Module.load (internal/modules/cjs/loader.js:600:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
      at Function.Module._load (internal/modules/cjs/loader.js:531:3)
      at Module.require (internal/modules/cjs/loader.js:637:17)
      at require (internal/modules/cjs/helpers.js:22:18)
      at Object.&lt;anonymous&gt; (/Users/asdf7/Desktop/asdf7/index.js:2:16)
  </code></pre>
  
  <p>This works:</p>
  
  <p><code>router.get('/watchdog', middleware, middleware2, watchdogController.ping)</code></p>
  
  <p>But now I can't see any roles in middleware2 ;( I need to be able to view the roles array in the <code>middleware2</code> function.</p>
  
  <p>I can't figure out what syntax to use... Can you guys help?</p>