How to get the last update date of a file using Node.js

Explore how to retrieve the last updated date of a file using Node.js

All file functions in Node.js are controlled byfsModule. This module exposes a method calledstatSync(), It will get the file details synchronously.

By calling it to pass the file path (relative to the file location or absolute path), it will return an object containing the following:mtimeproperty.

This is anDateThe object instance that contains the last modification date of the file.

const fs = require('fs')

const getFileUpdatedDate = (path) => { const stats = fs.statSync(path) return stats.mtime }

Take a lookJavaScript date guideLearn more about how to deal with Date objects (if needed).

Download mine for freeNode.js manual


More node tutorials: