I have a program that writes a lot of files very quickly, and I noticed that sometimes there will be extra brackets or text in json files sometimes. Here is how the program works: There is an array of emojis with some more information, and if that emoji doesn't already have a file for itself, it creates a new one. If there already is an existing file of that name, it will edit it. Code to write file:
function writeToFile(fileName, file){
return new Promise(function(resolve, reject) {
fs.writeFile(fileName, JSON.stringify(file, null, 2), 'utf8', function(err) {
if (err) reject(err);
else resolve();
});
});
}
I have tried using fs and graceful-fs and both have had this issue every couple hundred files, with no visible patterns. examples off messed up json:
...
],
"trade_times": []
}
]
}ade_times": []
}
]
}
That second "ade_times" shouldnt be there, and I have no idea why it is appearing. other times it just looks like this:
{
...
}}
with extra closing brackets for no reason. Not sure if this is an issue with my code, with fs, or something with my pc. If you need any more information I can provide that (more code, node.js version, etc). Thank you for your time :)