Skip to content

Instantly share code, notes, and snippets.

@anshuraj
Created April 25, 2020 12:08
Show Gist options
  • Save anshuraj/d513b2b01e930b40714f37a549c5a85b to your computer and use it in GitHub Desktop.
Save anshuraj/d513b2b01e930b40714f37a549c5a85b to your computer and use it in GitHub Desktop.
Make API call in node js using https module
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