I am missing something simple in Node, I have a function that needs to be exported, and return a value, async. I am not sure how in Node to have it "wait" before returning the value, I am apparently spoiled with front end javascript and databinding...
The code below will not wait for users to have the data back (pusher is a rest call) so it is always undefined.
exports.getMembers = function(channel) {
var users;
pusher.get( { path: '/channels/'+channel+'/users', params: {} },
function( error, request, response ) {
if( response.statusCode === 200 ) {
var result = JSON.parse( response.body );
users = result.users;
return users;
}
else {
console.log(error);
}
}
);
//return users;
};