Created
April 25, 2020 12:08
-
-
Save anshuraj/d513b2b01e930b40714f37a549c5a85b to your computer and use it in GitHub Desktop.
Make API call in node js using https module
This file contains 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
async function getData(url) { | |
return new Promise((resolve, reject) => { | |
https.get(url, (res) => { | |
let data = ''; | |
res.on('data', (chunk ) => { | |
data+= chunk; | |
}) | |
res.on('end', () => { | |
data = JSON.parse(data); | |
resolve(data); | |
}); | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment