Node.js fs stat() get file information

Description

Node.js fs stat() get file information

var fs = require('fs');

console.log('Going to get file information');
fs.stat('input.txt', function (err, stats){
  if (err) {/*from   www  . j  av  a2  s .co m*/
    return console.error(err);
  }
  console.log(stats);
  console.log('Got file into successfully !');
  
  // Check file type
  console.log('Is File ?' + stats.isFile());
  console.log('Is Directory ?' + stats.isDirectory());
});



PreviousNext

Related