find the last modified date of a json file in javascript

To find the last modified date of a JSON file in JavaScript, we can use the fs (file system) module in Node.js. Here's an example code snippet that demonstrates how to do it:

index.tsx
const fs = require('fs');

const filePath = 'path/to/file.json';

fs.stat(filePath, (err, stats) => {
  if (err) {
    console.error(err);
    return;
  }
  
  const lastModified = stats.mtime;
  console.log(`Last modified date: ${lastModified}`);
});
252 chars
14 lines

In this code, we use the fs.stat() method to retrieve the statistics for the file at the specified path. The stats object contains information such as the file size, creation date, and last modified date. We extract the mtime (last modified) property from the stats object and log it to the console.

Note that this code is for use in a Node.js environment, and may not work in a browser context. Additionally, make sure to replace the filePath variable with the actual path to your JSON file.

gistlibby LogSnag