I am trying to keep some backups in a folder. I want to keep a backup of 30 JSONs at any time, JSONs are being added hourly. If the number of files in the folder is > 30 I want to delete the older files. Is this possible with nodejs?
This is what I've got so far:
ipcMain.on("BACKUP_TO_DISK", function(event, arg) {
var date = new Date();
var json = JSON.stringify(arg);
fs.writeFile("./backup/" + date.yyyymmddhh()+ "_" + arg.prefix + "_backup.json", json, "utf8", function() {
console.log("Successfully Saved.");
});
});
and its being called from my React app like so:
this.interval = setInterval(() => {
var data = this.props.data.get("data");
var prefix = this.props.preferences.get("savePrefix");
var counter = this.props.data.get("counter");
var path = this.props.preferences.get("path");
console.log("BACK")
this.props.backupToDisk(data, prefix, counter, path);
}, 60000 * 30 ); //every half an hour