I'm practicing NodeJS and working on a small application that has an endpoint that stores json objects to text files and also has the ability to search for objects in files. I'm using a single file for that purpose, I know I should be using multiple files for many considerations, but lets consider the case of having a single storage text file.
As far as I understand, (Not 100% sure) that NodeJS is single threaded, and it is not possible that two simultaneous API calls would update the file at the same time since each process of them will be in a single separate thread.
So is my understanding correct? or there is a possiblitiy that a file gets updated simultaneously which will cause data integrity violation? and if yes, how to handle this ? Is there a way to lock a file until the process completes ?