Reputation: 531
I'm building a node.js application using express framework. The app routes are defined in separate files, so basically I have one router per resource. Here's an example:
app.js
var fooRoutes = require('./fooRoutes.js');
...
router.use('/users/:id/foos',fooRoutes);
fooRoutes.js
var fooController = require('./../controllers/fooController.js');
router.get('/', function(req, res) {
fooController.getFoos(req, res);
});
fooController.js
var FooController = function() {
this.getFoos = function(req, res) {
var foos = [];
fooService.findFoosByUser(req.params.id, function(err, recordset) {
if (err) {
res.send(400, err);
}
res.send(200, recordset);
});
};
};
The problem is that I cannot get the id
parameter from fooController. If I try to log it from the app file, I can get it. I guess it's because the route at that point recognizes it as a parameter.
Is there a way to get that parameter from fooController
?
Upvotes: 0
Views: 68