Yngvarr

Generation

generate functionThu, 06 Apr 2023

get page html

const getPage = url => new Promise((resolve, reject) => { http.get(url, (res) => { if (res.statusCode === 200) { let data = ''; res.on('data', chunk => { data += chunk; }); res.on('end', () => { resolve(data); }); } else { reject(new Error(`Status Code ${res.statusCode}`)); } }).on('error', err => { reject(new Error(err)); }); }); getPage(url).then(body => { console.log(body); }).catch(err => { console.error(err); });

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant