I have multiple users logged in at the same time, and they can write the same file simultaneously. How can I prevent collision for a file when multiple users are writing on a single file in nodejs.
Assuming you only have one node process the simples solution would be to use fs.writeFileSync.
The proper way to do it is to use rwlock to properly lock file so that only one process at a time can write to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With