I skipped that the curr and prev variables that were returned from fs.watchFile were instances of fs.Stats . This would be the best solution:
var fs = require('fs'); fs.watchFile('file', function (curr, prev) { console.log(curr.size); });
However, starting with Node v0.8.0, fs.watchFile no longer uses IOWatcher , and now uses statistics polling, which is slow and does not provide real-time updates. This has been discussed on GitHub .
From Node changelog :
Deprecated iowatcher, fs: fix fs.watchFile () (Ben Noordhuis)
Instead, an alternative solution is now fs.watch and fs.stat :
var fs = require('fs'); fs.watch('file', function (curr, prev) { fs.stat('file', function (err, stats) { console.log(stats.size); }); });
source share