last modified file date in node.js

后端 未结 4 779
悲&欢浪女
悲&欢浪女 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:44

    For node v 4.0.0 and later:

    fs.stat("/dir/file.txt", function(err, stats){
        var mtime = stats.mtime;
        console.log(mtime);
    });
    

    or synchronously:

    var stats = fs.statSync("/dir/file.txt");
    var mtime = stats.mtime;
    console.log(mtime);
    

提交回复
热议问题