Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created May 24, 2019 17:15
Show Gist options
  • Save jrobinsonc/dc8bbe1a8a120132a5c888e6502a262d to your computer and use it in GitHub Desktop.
Save jrobinsonc/dc8bbe1a8a120132a5c888e6502a262d to your computer and use it in GitHub Desktop.
const fetch = options =>
new Promise((resolve, reject) => {
require('https').get(options, function(response) {
let body = '';
if (response.statusCode !== 200) {
reject(
new Error(`Request failed. Status code: ${response.statusCode}`),
);
response.resume();
return;
}
response.on('error', err => reject(err));
response.on('data', chunk => (body += chunk));
response.on('end', () => resolve(body));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment