Reputation: 20591
I'm setting up a build system using node modules and npm scripts - no gulp, etc.
I need to determine if two files are equal, before copying unnecessarily. When I used to use gulp I used the gulp-changed
plugin. I need something like that.
How could I do this in plain node?
I couldn't find an existing npm module that does this. I also checked the fs
module but didn't find anything I could use.
I need something like this: function hasChanged(file1, file2) { /* ... */ }
but I'm not sure how to compare the files.
UPDATE
Using the advice given so far, this problem seems simple enough to code myself, so I'm doing that. But if you know of a node module that does this already, I'd appreciate it.
Upvotes: 0
Views: 1024
Reputation: 349
You might use fs.stat function to get file info, and compare mtime to see if they differ. I also recommend you to lookup the sourcecode of gulp-change, its actully just a few lines of code.
https://github.com/sindresorhus/gulp-changed?files=1
Upvotes: 1