Skip to content

Instantly share code, notes, and snippets.

@keif
Created September 17, 2025 17:50
Show Gist options
  • Save keif/faee0f369096fd74463a7c1fda05b13e to your computer and use it in GitHub Desktop.
Save keif/faee0f369096fd74463a7c1fda05b13e to your computer and use it in GitHub Desktop.
Helper function to get the Last Updated date on a file when publishing.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
function getFileTimestamp(filePath) {
try {
const stats = fs.statSync(filePath);
const mtime = stats.mtime;
return mtime.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error getting file timestamp:', error);
return null;
}
}
module.exports = { getFileTimestamp };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment