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
npmjs.com › package › text-diff
text-diff - npm
Compute a diff between two pieces of text with support for same-line diffs, and optionally display a visual diff as HTML. Module made from the text-diff-match-patch library.. Latest version: 1.0.1, last published: 11 years ago.
      » npm install text-diff
    
Published   Jul 19, 2015
Version   1.0.1
Author   Harrison Liddiard
🌐
npm
npmjs.com › package › diff
diff - npm
A JavaScript text diff implementation.. Latest version: 8.0.3, last published: 2 months ago. Start using diff in your project by running `npm i diff`. There are 8153 other projects in the npm registry using diff.
      » npm install diff
    
Published   Jan 12, 2026
Version   8.0.3
🌐
GitHub
github.com › kpdecker › jsdiff
GitHub - kpdecker/jsdiff: A javascript text differencing implementation. · GitHub
The value of the callback option should be a function and will be passed the computed diff or patch as its first argument. (Note that if the ONLY option you want to provide is a callback, you can pass the callback function directly as the options parameter instead of passing an object with a callback property.) maxEditLength: a number specifying the maximum edit distance to consider between the old and new texts.
Starred by 9.1K users
Forked by 526 users
Languages   JavaScript 64.7% | TypeScript 35.3%
🌐
npm
npmjs.com › package › text-file-diff
text-file-diff - npm
import TextFileDiff from 'text-file-diff'; const m = new TextFileDiff(); m.on('compared', (line1, line2, compareResult, lineReader1, lineReader2) => { // event triggered immediately after line comparison // but before +- event }); m.on('-', line => { // when a line is in file1 but not in file2 }); m.on('+', line => { // when a line is in file2 but not in file1 }); // run the diff m.diff('tests/file1.txt', 'tests/file2.txt'); // or run m.diffStream(stream1, stream2)
      » npm install text-file-diff
    
Published   Sep 06, 2023
Version   1.4.8
Author   noogen
🌐
npm
npmjs.com › package › fast-diff
fast-diff - npm
var diff = require('fast-diff'); var good = 'Good dog'; var bad = 'Bad dog'; var result = diff(good, bad); // [[-1, "Goo"], [1, "Ba"], [0, "d dog"]] // Respect suggested edit location (cursor position), added in v1.1 diff('aaa', 'aaaa', 1) // [[0, "a"], [1, "a"], [0, "aa"]] // For convenience diff.INSERT === 1; diff.EQUAL === 0; diff.DELETE === -1;
      » npm install fast-diff
    
Published   May 19, 2023
Version   1.3.0
Author   Jason Chen
🌐
GitHub
github.com › bhousel › node-diff3
GitHub - bhousel/node-diff3: A JavaScript library for text diffing and three-way-merge
node-diff3 is a Javascript library to find differences between two buffers, generate and apply patches, and perform 3-way merging between an original and two changed buffers.
Starred by 98 users
Forked by 13 users
Languages   JavaScript 97.4% | TypeScript 2.6% | JavaScript 97.4% | TypeScript 2.6%
🌐
Stack Overflow
stackoverflow.com › questions › 21470682 › how-to-render-text-diffs-with-human-readable-difference-highlighting-in-javascri
node.js - How to render text diffs with human readable difference highlighting in javascript - Stack Overflow
chardiff (https://npmjs.org/package/chardiff) which is based on diff, but it has a semantic filter designed for human readability: it looks better but still gives fragmented single-letter changes (where classic diff wont).
Find elsewhere
🌐
npm
npmjs.com › package › simple-text-diff
simple-text-diff - npm
a simple module for comparing text diff. Latest version: 1.7.0, last published: 6 years ago. Start using simple-text-diff in your project by running `npm i simple-text-diff`. There are 2 other projects in the npm registry using simple-text-diff.
      » npm install simple-text-diff
    
Published   Feb 28, 2020
Version   1.7.0
Author   houzhenghua
🌐
Tabnine
tabnine.com › home page › code › javascript › diff
diff JavaScript and Node.js code examples | Tabnine
jsDiff.diffWords(lineContent.trim(), mutantLineContent.trim()).map(stringDiff => { if (stringDiff.added) return chalk.bgGreen(stringDiff.value) else if (stringDiff.removed) return chalk.bgRed(stringDiff.value) else return chalk.inverse(stringDiff.value) }).join('')
🌐
npm
npmjs.com › search
jsdiff - npm search
A JavaScript text diff implementation.
🌐
npm
npmjs.com › package › @omrid01 › node-red-text-diff
@omrid01/node-red-text-diff - npm
text diff is a custom Node-RED node, which compares text blocks (by either lines, words, characters etc.).
      » npm install @omrid01/node-red-text-diff
    
Published   Aug 05, 2025
Version   0.3.0
Author   Omri Dayan
🌐
GitHub
github.com › liddiard › text-diff
GitHub - liddiard/text-diff: Visual JavaScript text diff library. CommonJS module created from https://code.google.com/p/google-diff-match-patch/.
This repository contains the diff functionality of the google-diff-match-patch library by Neil Fraser, turned into a node module which is suitable for requireing into projects.
Starred by 153 users
Forked by 22 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
npm
npmjs.com › search
keywords:diff - npm search
Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser. diff · difference · compare · change-tracking · flitbit• 1.0.2 • 7 years ago • 1151 dependents • MITpublished version 1.0.2, 7 years ago1151 dependents licensed under $MIT · 7,557,142 · JSON diff & patch (object and array diff, text diff, multiple output formats) json ·
🌐
GitHub
github.com › jhchen › fast-diff
GitHub - jhchen/fast-diff: A fast Javascript string diff
var diff = require('fast-diff'); var good = 'Good dog'; var bad = 'Bad dog'; var result = diff(good, bad); // [[-1, "Goo"], [1, "Ba"], [0, "d dog"]] // Respect suggested edit location (cursor position), added in v1.1 diff('aaa', 'aaaa', 1) // [[0, "a"], [1, "a"], [0, "aa"]] // For convenience diff.INSERT === 1; diff.EQUAL === 0; diff.DELETE === -1;
Starred by 714 users
Forked by 48 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Node-RED
flows.nodered.org › node › @omrid01 › node-red-text-diff
node-red-text-diff (node) - Node-RED
text diff is a custom Node-RED node, which compares text blocks (by either lines, words, characters etc.).
🌐
npm
npmjs.com › package › textdiff-create
textdiff-create - npm
This is a simple module for creating lean text diff deltas, based on the excellent fast-diff by Jason Chen.
      » npm install textdiff-create
    
Published   Apr 20, 2024
Version   1.1.11
Author   Ionut-Cristian Florescu
🌐
Npm
npm.io › package › text-diff
Text-diff NPM | npm.io
An array of differences is computed which describe the transformation of text1 into text2. Each difference is an array. The first element specifies if it is an insertion (1), a deletion (-1) or an equality (0).