How to Retrieve the Last Updated Date of a File Using Node.js
Learn how to use Node.js to get the last updated date of a file.
The fs
module in Node.js provides all the necessary file functions. One of these functions is statSync()
, which allows us to get file details synchronously.
To retrieve the last updated date of a file, simply call statSync()
and pass in the file path (either relative or absolute). It will return an object that contains the mtime
property.
The mtime
property is a Date
object instance that represents the last modified date of the file.
Here’s an example code snippet:
1 | const fs = require('fs'); |
If you need to work with the Date
object further, you can refer to our JavaScript Date guide.
Tags: Node.js, file handling, fs
module, last updated date