Created
September 13, 2018 15:35
-
-
Save tkssharma/5031c26ecb729ede0df9e0901124f92e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require("request"); | |
var userDetails; | |
function initialize() { | |
return new Promise(function(resolve, reject) { | |
// Do async job | |
request.get("https://api.github.com/users/tkssharma", function(err,resp,body) { | |
if (err) { | |
reject(err); | |
} else { | |
resolve(JSON.parse(body)); | |
} | |
}); | |
}); | |
} | |
function main() { | |
var initializePromise = initialize(); | |
initializePromise.then( | |
function(result) { | |
userDetails = result; | |
console.log("Initialized user details"); | |
// Use user details from here | |
console.log(userDetails); | |
}, | |
function(err) { | |
console.log(err); | |
} | |
); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment