In your user.route.js
, you need to export something like this :
module.exports = function (variable) {
return (req, res, next) => {
// your middleware
next()
}
}
Or with currying (https://wsvincent.com/javascript-currying/):
module.exports = variable => (req, res, next) => {
const myUsedVariable = variable + 1
res.send(myUsedVariable)
}
And if you're using express.Router:
var express = require('express')
var router = express.Router()
router.get('/', function(req, res) {
res.send('Birds home page')
})
module.exports = variable => {
// do something with your variable
router.use(function displayVariable(req, res, next) {
console.log(variable)
next()
})
return router
}