I'm trying to retrieve the last modified date of a file on the server using node.js.
I've tried
file.lastModified;
and
file.lastModifiedDate;
both come back as undefined.
As you can see, the mtime is the last modified time. you can use also sync version: fs. statSync(path) returns same object.
The lastModified() method of the File class returns the last modified time of the file/directory represented by the current File object. You can get the last modified time of a particular file using this method.
Javascript has provided a command called document. lastModified to get the instance when the document is last modified. This command will provide the exact date and time of modification.
The fs. statSync() method is used to synchronously return information about the given file path.
You should use the stat function :
According to the documentation :
fs.stat(path, [callback])
Asynchronous stat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. It looks like this:
{ dev: 2049 , ino: 305352 , mode: 16877 , nlink: 12 , uid: 1000 , gid: 1000 , rdev: 0 , size: 4096 , blksize: 4096 , blocks: 8 , atime: '2009-06-29T11:11:55Z' , mtime: '2009-06-29T11:11:40Z' , ctime: '2009-06-29T11:11:40Z' }
As you can see, the mtime
is the last modified time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With