0

New to node.js. My requirement is to change file name of a CSV file to a different path (new file) every day at 15 minutes past midnight. Presently using fast-csv to write the output. How can I change the path of the file dynamically to another path and CSV file at the above mentioned time, such that the new file takes over the writing of output and the previous one is saved and closed. How can I accomplish this?

Edit: I can use node-schedule for the scheduling part.

Mallik Kumar
  • 540
  • 1
  • 5
  • 28

1 Answers1

0

For the time use https://www.npmjs.com/package/node-schedule

var event = schedule.scheduleJob("0 15 0 * * 0-6", function() {
  yourFunctionToChangeTheCSVPath();
});

This should be 15 past midnight.

  • Thanks @Vanilla_Chan...I am aware of the way to schedule it. – Mallik Kumar Sep 05 '19 at 10:51
  • Then just change the path, or the name of the file in the function, where is the problem? https://stackoverflow.com/questions/22504566/renaming-files-using-node-js @Mallik Kumar – Vanilla_Chan Sep 05 '19 at 11:03
  • @Chan if I cannot rename the current file being written into. I want to close the file properly and make a new path to another new file and point fast-csv to write to it. Can you help me do that? – Mallik Kumar Sep 05 '19 at 11:09
  • @Mallik Kumar Kinda hard without seeing your code, just update your question. – Vanilla_Chan Sep 05 '19 at 12:05