I have made a basic web scrapper that collects data from a webpage about apartment prices. Each time the script is run it generates an array that contains objects of the format:
apartments = [{
date: "1/1/2022",
time: "7:30 AM",
floorPlanName: "Example",
bedNumber: "1",
floorPlanSize: "800",
floorPlanPrice: "1800"
}]
I want to be able to save this data to my hard drive so I can analyze this data in excel. (I currently have it to save as a CSV). I want new data generated to be added to the CSV every time the script is ran.
I'm using nodeJS to do all this. What is the best way to update this file every time I run the script?
You should be able to use objects-to-csv for this use case
const ObjectsToCsv = require('objects-to-csv');
const sampleData = [{ id: 1, text: 'this is a test' }];
new ObjectsToCsv(sampleData).toDisk('./test.csv', { append: true });