From Express's error handling docs:
Define error-handling middleware functions in the same way as other middleware functions, except error-handling functions have four arguments instead of three:
(err, req, res, next). For example:app.use(function (err, req, res, next) { console.error(err.stack) res.status(500).send('Something broke!') })
It seems that Express's .use(middlware) inspects the middleware function's length to see how many arguments it takes, and if four, then it treats it differently to other middleware functions, passing it an error as the first argument.
This is incompatible with modern linting setups like XO or Airbnb, as it forces you to define an extra trailing parameter tha doesn't get consumed (i.e. next in the above example). Also, unused trailing parameters might get removed by some automated code transformations, which is just something I don't want to worry about. In my opinion, Function.prototype.length is best kept for metaprogramming/introspection as opposed to affecting real production behaviour.
Is there any other, more explicit way to define an error handler in Express, that doesn't force you to imply intended functionality through the number of parameters your function takes?