Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: Determine file size on modification

I'm watching a file in Node.js and would like to obtain the size of the file each time it changes. How can this be done with fs.watchFile?

This is what I'm currently doing:

fs.watchFile(file, function(curr, prev) {
  // determine file size
});
like image 455
hexacyanide Avatar asked Nov 30 '22 02:11

hexacyanide


1 Answers

var fs = require('fs');

fs.watchFile('some.file', function () {
    fs.stat('some.file', function (err, stats) {
        console.log(stats.size);
    });
});
like image 59
Vadim Baryshev Avatar answered Dec 06 '22 13:12

Vadim Baryshev