Thursday 16 March 2017

Cannot deal with nodejs async request

var request = require("request");

var options = {...};

var rez = request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(JSON.parse(body)['access_token']);
    fu(JSON.parse(body)['access_token']);
});

var fu = function (result) {
    return result;
};

console.log(rez);

I cannot figure out the way to get the JSON.parse(body)['access_token'] and save it.

this one console.log(JSON.parse(body)['access_token']); give's me normal output of my 'access_token'.

but fu(JSON.parse(body)['access_token']); give's me whole description of this request.

i cannot figure the way to store and pass the 'access_token'.



via funafuna

No comments:

Post a Comment