I'm using express
in Node to create a simple web app. The code looks like this:
var get_stuff = function (callback) {
another.getter(args, function (err, data) {
if (err) throw err;
data = do_stuff_to(data);
callback(data);
});
};
app.get('/endpoint', function (req, res) {
get_stuff(res.send);
});
When I run this, though, I get this error: TypeError: Cannot read property 'method' of undefined at res.send
. The express code that's breaking starts like this:
res.send = function (body) {
var req = this.req;
var head = 'HEAD' == req.method;
It seems to me that the way I've constructed the callbacks is losing this
in the send
method. But I'm not sure how to fix it. Any tips? Thanks!