const jsdom = require("jsdom");
const dom = new jsdom.JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
dom.window.document.querySelector("p").textContent; // 'Hello world'
const htmlparser = require("htmlparser2");
const parser = new htmlparser.Parser({
onopentag: (name, attrib) => {
if (name=='p') console.log('a paragraph element is opening');
}
}, {decodeEntities: true});
parser.write(`<!DOCTYPE html><p>Hello world</p>`);
parser.end();
// console output: 'a paragraph element is opening'