I wrote a javascript(nodejs+express) program to download a html document from a given url. I converted into a DOM object using parse5, jsdom, cherrio(only one). Now I need to send the response(the DOM object) to an ajax call. But when I try
var document = jsdom(data); //can use any of these three
var $ = cheerio.load(data);
var document3 = parse5.parse(data);
return res.send({'data':document3});
It gives an error 'converting circular structure to json', which is obvious because I'm trying to convert a DOM object to JSON.
My requirement is to parse the HTML and send the DOM as response because I need to use the DOM on client side. What should be approach?