Reputation: 170
I have a text file which has information on all Wifi connections (like ssid, mac no, strength, etc.) which were in my laptop range 2 minutes ago. And now I run the code again and get information of current wifi connections in a string. I want to compare that text file and this string and want to know the difference. Are there any new wifi connections or not?
Please can someone help me or give me piece of code for this purpose?
Upvotes: 0
Views: 11340
Reputation: 2693
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
Upvotes: -1
Reputation: 875
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])
Upvotes: 5