Thanks for the suggestion. <3
I already converted it from appendFileSync to fileWriteStream
These are concepts you might find it useful to study and learn as well as experiment with.
Non-blocking is a crucial concept in JS that gives it much of it's performance (async). While this write operation is happening everything is blocked and nothing can happen.
By also writing to the file like that, it's opening it everytime, writing the line then closing it. You can instead open it, write all the lines, then close it.
fs.writeFileSync(path, JSON.stringify(data)) is enough in this case or fs.writeFileSync(path, JSON.stringify(['create', data])).
You can probably also get away with just \n for lines in many cases. Line endings only matter these days in niche situations and \n works well as a standard.
You should check options to see if writeFileSync supports locking but otherwise you may need to look up the lock functions. If it's not concurrency safe and is non-blocking it might need to say that in the documentation otherwise using it can mess up someone's application either due to data corruption or routine freezes.
It might suit your app, IE, you only run it once at a time per path and either can tolerate delays or are working with small amounts of data but for others it would not be even half way stable.
Once you learn it and apply it once it's like riding a bicycle. It's much more enjoyable though if you write some minimal benchmarks and tests. It's then nice to see it doing better so you get a reward for it.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.