One way would be to check for their inode values using fs.stat().
What are a few other ways to achieve this? Is there a NodeJS method, that I should know of; or any third-party modules that you might be using for doing this?
Personally, it’s very convenient for me to compare files file compare tool with it, I can quickly compare, distinguish and even merge text files or folders
Denny Trebbin
Lead Fullstack Developer. Experimenting with bleeding-edge tech. Irregularly DJ. Hobby drone pilot. Amateur photographer.
If possible, use a daemon on Linux. Let it watch a particular folder and generate SHA hashes for each file that gets stored in that folder. Then just access and compare each hash of the files you need to check for equality.
It has some advantages. When using Node.js, it doesn't block the event loop when hashing huge files. My daemon follows symlinks. Copying a symlink into that watched folder cost virtually no time.
I had used a sperate Node.js process for that task before I found the daemon thing. Watching a folder for file change events then loading the file and hashing it via
cryptomodule bundled with Node.js. Comparing the hashes answers the question for equality.Maybe someone published a ready to go package already, but this task is easier than trying to find a suitable solution on npmjs.org ;-)
Edit: I just remembered that I used https://github.com/h2non/jsHashes for the Node.js based hashing project. It is fast, the API is simple, and it has no dependencies.