Cheerio get element outer html
Change your map func to
let htmlPages = pages.map(page => $.html(page));
according to docs
If you don't have easy access to the original $ object, the following also works
function outerHTML (element) {
var index = element.index();
var parent = element.parent().clone();
var child = parent.children()[index];
parent.empty();
parent.append(child);
return parent.html();
}