0

I am kind of a beginner to javascript. This is a javascript problem, but for the record, this is a program done in node.js using hapi and mongoose. Tables is a model in mongoose.

My problem is that I want to set the response to a value so I can send it later:

handler: function (request, reply) {
    var response;
    Tables.find(function find(err, mesas) {
        if (err) 
            response = reply({ error: err});
        else 
            response = reply({mesas : mesas}).hold;
        });
    }
    response.send();
}

For some reason, server returns "undefined does not have method 'send'", and I guess that is because it is referenced inside an anonymous function. This brings a couples of thoughts to me:

1) Am I writing this in a non javascript idiomatic way?
2) What is the best approach to to makes this work?

EDIT: The response.send() call was actually outside of the Tables.find(...).

Guido Tarsia
  • 1,962
  • 4
  • 27
  • 45

0 Answers0