Friday, 26 May 2017

Get return from database callback in NodeJS

Hello i would like to return data from a callback function like this :

var data = "test";

database.users.get("username-test", function (err, value) {
  if (err) {
    console.log("error: " + err);
    data = "error"
  }

  data = "success";
})

console.log(data);
// >>> "test"

When i run the code, data still have test as value.

Thanks!



via L.X

No comments:

Post a Comment