Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
All the file functions in Node.js are provided by the fs module. This module exposes a method called statSync(), which gets the file details synchronously.
When you call it and pass a file path (relative to the current location or absolute), it returns an object that contains the mtime property.
That is a Date object instance that contains the file last modified date.
const fs = require('fs')
const getFileUpdatedDate = (path) => {
const stats = fs.statSync(path)
return stats.mtime
}
See the JavaScript Date guide for more on working with the Date object.