Skip to content

Instantly share code, notes, and snippets.

@maggiben
Created July 7, 2021 20:09
Show Gist options
  • Save maggiben/e8508d3b7fe3ef4c5e01b82319eccfb5 to your computer and use it in GitHub Desktop.
Save maggiben/e8508d3b7fe3ef4c5e01b82319eccfb5 to your computer and use it in GitHub Desktop.
Read URL (transform stream -> promise)
private readUrl(url: string): Promise < string > {
return new Promise((resolve, reject) => {
https.get(url, (response) => {
response.setEncoding('utf8');
let body = '';
response.on('data', (data) => {
body += data;
});
response.on('end', () => {
resolve(body);
});
response.on('error', (error) => {
reject(error);
});
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment