select csv file and for each line add a new column called situation and for each line fill the situation with anything and move the new csv to destination in javascript

index.tsx
const fs = require('fs');
const csv = require('csv-parser');

// select csv file
// in this case, we're hardcoding the file path for example purposes
const filePath = 'path/to/csv/file.csv';

// create an array to hold our modified data
const newData = [];

// open a read stream for the csv file
fs.createReadStream(filePath)
  .pipe(csv())
  .on('data', row => {
    // for each row of data, add a new "situation" column and set it to "in progress"
    row.situation = 'in progress';
    // push the modified row into our new array
    newData.push(row);
  })
  .on('end', () => {
    // once we've processed all of the data, write the new csv file to our destination
    const newFilePath = 'path/to/new/csv/file.csv';
    const csvWriter = require('csv-writer').createObjectCsvWriter({
      path: newFilePath,
      header: Object.keys(newData[0]).map(field => ({id: field, title: field})),
    });
    csvWriter.writeRecords(newData)
      .then(() => console.log('New csv file written to destination.'))
      .catch(err => console.error(err));
  });
1058 chars
31 lines

In the code, we use the csv-parser library to parse the csv file, then modify each row of data by adding a new "situation" column and setting it to "in progress". We store the modified rows in an array called newData. Then we use the csv-writer library to write the new csv file to our specified destination.

gistlibby LogSnag