Monday, 24 April 2017

How to get file created dat using fs module?

I have linux server where i have logs file that are being created with winston rotation , so filename has filename and created date, so you can see first file in data server20170414181405.log created on 2017-04-14 but using fs.stats.birthtime its giving fileDate Apr-19-2017. How can i get accurate file created date working on linux ?

cron.js

fs.stat(filePath, function (err, stats) {
  if (err) return cb2(err);
   var fileInfo = { fileDate: stats.birthtime, filename: file };
    console.log(fileInfo);
});

data

  { fileDate: Wed Apr 19 2017 00:51:56 GMT-0400 (EDT),
    filename: 'server20170414181405.log' },
  { fileDate: Wed Apr 19 2017 00:52:04 GMT-0400 (EDT),
    filename: 'server20170414212655.log' },
  { fileDate: Wed Apr 19 2017 00:52:07 GMT-0400 (EDT),
    filename: 'server20170415023845.log' },



via hussain

No comments:

Post a Comment