last modified file date in node.js

后端 未结 4 781
悲&欢浪女
悲&欢浪女 2020-12-24 10:35

I\'m trying to retrieve the last modified date of a file on the server using node.js.

I\'ve tried

file.lastModified;

and

4条回答
  •  孤城傲影
    2020-12-24 10:49

    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.

提交回复
热议问题