I have the following code in my Node.js project:
var response;
if (theInput == 1) {
models.User.find({
usersNumber: usersNumber,
active: true
}, function (err, user_data) {
response = "Number is 1";
});
} else if (theInput == 2) {
response = "Number is 2";
} else {
response = "Number is n/a";
}
return response;
I am having a hard time setting response when theInput = 1. Response is undefined when it gets returned. I don't want to set it outside of the model.find function, because my actual response text (in my real code) is based on some of that data.