I am trying to get user data from github using an url, I am new to dealing with APIs. I tried to follow github-api, but the code there makes little sense to me. I understand the concept of promises, so I tried to couple up this stackoverflow answer with promises and tried to implement it as below. I am working with node.
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var request = new XMLHttpRequest();
function pr() {
return new Promise(function(resolve, reject) {
request.open('get', 'https://api.github.com/users/$username')
request.send();
resolve(request.response);
});
}
var gitpr = pr();
gitpr.then(function() {
console.log(request.response);
})
My request.response
[[PromiseValue]]
is undefined on running the code in node.
Whereas the result in console is correct if I follow this stackoverflow answer(same as above).