As far as i understand you want to compare two text files (which is not JavaScript, arrays or node.js related). You can use online tools like Diff checker and DiffNow, or if you have installed SVN for example it provides quite good diff tool.
However if your question is how to do it with node.js the diff npm module is looking as the easiest solution.
Edit:
You can read the files using:
fs.readFile(filename, callback)
And compare their characters by:
JsDiff.diffChars(file1Str, file2Str, callback])
Answer from Chavdar Slavov on Stack Overflow
» npm install text-diff
» npm install diff
As far as i understand you want to compare two text files (which is not JavaScript, arrays or node.js related). You can use online tools like Diff checker and DiffNow, or if you have installed SVN for example it provides quite good diff tool.
However if your question is how to do it with node.js the diff npm module is looking as the easiest solution.
Edit:
You can read the files using:
fs.readFile(filename, callback)
And compare their characters by:
JsDiff.diffChars(file1Str, file2Str, callback])
You can use native fs library:
const fs = require('fs');
var str1 = fs.readFileSync('file1', 'utf-8');
var str2 = fs.readFileSync('file2', 'utf-8');
str1 === str2
// returns true if same content
» npm install text-file-diff
» npm install fast-diff
Maybe this will help you — jsdiff
I'm a fan of google diff match patch. You can try out an example here.
There are different cleanup option to tweak the level of commonality between the diffs. I don't like the semantic cleanup option as I find it's too aggressive, but the efficiency cleanup with a value of 10 works well for me.
» npm install simple-text-diff
» npm install @omrid01/node-red-text-diff
» npm install textdiff-create