I have a JSON file in which I want to create a series of backups in a period of 5 minutes, at this moment, I have a program running with NodeJS that reads and writes a file defined by:
let points = JSON.parse(fs.readFileSync('./points.json', 'utf8'));
But I have noticed that when my program gets an unexpected error and it closes suddenly, it leaves the file "open" and all the content is deleted. What I would like to do is a function in which each period, save all the contents of the file ./ points.json and that after having written and saved it, that closes it (so if the program "crashe ", the content is not deleted) and the next autosave, create another new file.
Preferably, backup copies should be "points" + timestamp.
Thanks in advance.