ryu1kn / csv-writer

Convert objects/arrays into a CSV string or write them into a CSV file
https://www.npmjs.com/package/csv-writer
MIT License
246 stars 39 forks source link

Using on scheduler the value keep appending with existing one #40

Closed PrasannaBrabourame closed 4 years ago

PrasannaBrabourame commented 4 years ago

const job = new CronJob('/30 ', async function () { var data = [{"place": "Puducherry","state":"PY"},{"place":"Chennai","state":"TN"}] await csv.csvWriter.writeRecords(data) }

By executing this first time csv looklike place,state puducherry,PY chennai,TN

By executing this second time csv looklike place,state puducherry,PY chennai,TN puducherry,PY chennai,TN

By executing this third time csv looklike place,state puducherry,PY chennai,TN puducherry,PY chennai,TN puducherry,PY chennai,TN

Similarly the value keep on increasing

ryu1kn commented 4 years ago

Hi @PrasannaBrabourame , that's actually the expected behaviour. As long as you use the same instance of csv writer, you can keep writing to the same file.

If you want to create a new file each time you run the cron job, create a new instance in the CronJob's callback (i.e. the 2nd argument).

Let me know if this doesn't solve your problem 😉