I have a case where I send a request to a server and record the response. Then I craft the request and send it to server one more time and compare the response with the earlier recorded response.
I am using node.js and I want to know is there any best routine to compare HTML response in node.js which can directly point me the differences in both HTML responses.
Take a look at jsdiff, it can return to you the differences between two pieces of text, or HTML in your case, at a few different levels (chars, words, lines).
You can use a combination of jsdom and dom-compare:
var compare = require('dom-compare').compare,
jsdom = require('jsdom');
// Those are the HTML fragments that we want to compare:
var expectedHTML = '<div><i>m</i><b>q</b></div>';
var actualHTML = '<div><i>h</div>';
var expectedDOM = jsdom.jsdom(expectedHTML);
var actualDOM = jsdom.jsdom(actualHTML);
var result = compare(expectedDOM, actualDOM);
console.log('diff array:', result.getDifferences());
// we can use a reporter to pretty-print the result:
var reporter = require('dom-compare').GroupingReporter;
console.log(reporter.report(result));