find the last modified date of a csv file in javascript

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

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

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

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

Here, we first require the fs module, and then specify the path to the CSV file using the filePath variable. We then use the fs.stat() method to get the file statistics, which includes information like the file size, creation time, and last modified time.

The stats object that's returned by fs.stat() has a mtime property, which represents the last modified time of the file. We can then create a new Date instance from this time, and format it as desired.

Note that the fs.stat() method is asynchronous and accepts a callback function that's called with the stats object. If there's an error, it will be passed as the first argument of the callback function.

gistlibby LogSnag