I can’t find any decent documentation on this that contains any depth when requiring with app.resource.
The only information that I can find is creating the variable within the current file. Here
The current code that I have is below:
var favs = app.resource('favs', require('./modules/favs'));
favs.map('get', '/user', favs.buses);
However it comes back saying that it is undefined?
In the module favs I have.
exports.buses = function (req, res) {
res.render('favs/buses', {
title: 'Bus Stops'
});
});
You have a syntax error in
favs.js: The last right bracket)is redundant.Apart from that, you seem to conflate the actual module with the resource object you get back from
app.resource. You want to pass a reference to the request handler you want to invoke when a visitor hits the path (in your case,/favs/user). So what you want is something like:If you feel a little lost dealing with
express-resource, I encourage you to begin with plain express, and only start using express-resource when you are more familiar with how express works. TJ’s helper modules have a tendency to be lacking in documentation, and you should use them only if you feel comfortable reading the code, IMO.