Categories
JavaScript Answers

How to get last modified file date in Node.js?

Spread the love

To get last modified file date in Node.js, we use the stats.mtime property.

For instance, we write

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

to call fs.stat to get the file metadata for the /dir/file.txt file.

And we use stats.mtime to get the last modified date.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *