Skip to content

Instantly share code, notes, and snippets.

@joekiller
Created December 7, 2021 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joekiller/bd43c23f0a0077163bfc6d8429879a6b to your computer and use it in GitHub Desktop.
Save joekiller/bd43c23f0a0077163bfc6d8429879a6b to your computer and use it in GitHub Desktop.
https.get typescript nodejs
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