Created
December 7, 2021 23:55
-
-
Save joekiller/bd43c23f0a0077163bfc6d8429879a6b to your computer and use it in GitHub Desktop.
https.get typescript nodejs
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
const data: string = await new Promise((resolve, reject) => { | |
https.get(targetUrl, (res) => { | |
res.setEncoding('utf8'); | |
let rawData = ''; | |
res.on('data', (chunk) => { | |
rawData += chunk; | |
}); | |
res.on('end', () => { | |
try { | |
resolve(rawData); | |
} catch (e) { | |
console.error(`couldn't parse ${rawData}`); | |
reject(e); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment