Syed Rashid Mehmood
Syed Rashid Mehmood

Reputation: 3

Using async calls data in non-async Javascript, Node to javascript variable copy

I am fairly new to async scripts, I encountered a situation where our code is using an api through node.js, the api documentation provide the following usage, and it does work in a js file executed with nodejs.

var allpermissionsofthisEmployee = employee.permissions({ appId: cuurrappid });
allpermissionsofthisEmployee .then(console.log);
//this shows a json array of json objects on console.
function function2(permissioninfo) {
//Some code to work on this info
//ideally allow saving of part of that json object into MSSQLDB
}

What we have to do is, some how collect information that is being displayed on console into a variable and pass that to function2.

Upvotes: 0

Views: 31

Answers (1)

Vipin Kumar
Vipin Kumar

Reputation: 6546

Simply use function2 instead of console.log. then take a function as callback and execute it. You need to read more about using promises.

var allpermissionsofthisEmployee = employee.permissions({ appId: cuurrappid });
allpermissionsofthisEmployee.then(function2);

function function2(permissioninfo) {
  // Some code to work on this info
  // ideally allow saving of part of that json object into MSSQLDB
}

Upvotes: 2

Related Questions