I'm completely aware that this is probably covered in another thread however, i'm new to JavaScript and Node and not completely sure what i'm looking for.
I'm working with a presentation layer called Domo and attempting accessing their API in order to export data. Part of accessing their data is to establish a token to connect with.
I've successfully been able to make the call and console log the value, but i'm unable to push the value to an object such as an Array. I believe this is an anonymous function and been searching all over trying to find a way to use it. My research has been everything from closures, callbacks, let, return and immediately invoked functions but i'm missing something here. Can anyone point me in the right direction?
**Here is the code:**
var http = require("https");
var tokenoptions = {
"method": "GET",
"hostname": "api.domo.com",
"port": null,
"path": "/oauth/token?grant_type=client_credentials&scope=data%20user",
"headers": {
"Accept":"application/json",
"Authorization": "Basic MyClientAndSecretGoesHere"
}
}
var req = http.request(tokenoptions, function (res) {
var chunks = [];
var token = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
**End Code**
The Console.log(body.toString()) is the value i want but how do i assign this to an array or object? Is this an anonymous function?
I'd really appreciate the help and apologize in advance if this is a duplicate post. With the age of this site, I don't see how any new post couldn't be.