util.promisify
https://nodejs.org/api/util.html#util_util_promisi... const http = require('http');
const fetch = url => new Promise((resolve, reject) => http.get(url, res => {
if (res.statusCode !== 200) {
reject(`Request Failed.\nStatus Code: ${res.statusCode}`);
return;
}
res.setEncoding('utf8');
const buffers = [];
res.on('data', chunk => buffers.push(chunk));
res.on('end', () => resolve(Buffer.concat(buffers)));
}));
fetch('http://site.com/')
.then(body => console.log(body))
.catch(err => console.error(err));