With Node.js, you should use the Continue Transfer Style (CPS). This example cannot work because the callback specified as the get parameter has not yet completed when "console.log (users)" is executed.
The notEnterUsers function must have a callback parameter and call it after filling in the user variable. Sort of:
, notEnterUsers: function(callback){
var users;
this.store.get("users",function(err,result){
var result = JSON.parse(result);
users = result.filter(function(element, index, arr){
return (element.status === 0);
});
callback(users);
});
}
Node.js is fundamentally asynchronous, and your scripts should try to hug it, and not try to simulate synchronous behavior.
source
share