This question is very related to this.
In my module I use following:
const express = require('express'),
router = express.Router();
...
module.exports = router;
And I need access to objects in the app.js file. Something like const routes = require(./routes/route.js)(data)
.
What I tried
module.exports = router(data)
But thanreq
is undefined in the router object.Made an instance of
route
in app.js after requiring it. But this results in the same error message. (Like this:
var route = new Route();
route.data = data
- Pretty much the same like in the article I mentioned, but I'm not sure what I have to do with the router object. This does not work:
module.exports = router(data){
// all routes
};
Additional information
I normally use routes like this in app.js
const route = require('route.js');
app.use(route);