1

I have a directory that has files. These files are created with one process everytime a trigger happens. Another NodeJS process tries to list down new files added and parse its content and push it to a remote DB.

The problem that NodeJS app tries to access one of the files while it is still locked by the other process and it causes my node app to throw an exception

Error: ENOENT: no such file or directory

Now I am trying to add a check to check if a file is locked by another process or not. If not then I will go ahead and process its content.

I tried to use lockfile and proper-lockfile npm modules but still, I am getting the same error.

Would you please let me know if there is any other way to check if the file is locked by another process in NodeJS?

  • Can you clarify what the 'app', and what the 'other process' refers to in your 2nd paragraph? – Xenyal Aug 08 '18 at 05:35
  • Just wrap your code which accessing file with `try{...}catch(e){...}`. You will get exception if your file is still locked. – NoobTW Aug 08 '18 at 05:42
  • 1
    Are you sure you've diagnosed the problem correctly? Wouldn't you get a `EBUSY` if the file was locked? – Sam H. Aug 08 '18 at 06:37
  • Possible duplicate of [Node Js: Test to see if a file is locked for editing by another process](https://stackoverflow.com/questions/37690321/node-js-test-to-see-if-a-file-is-locked-for-editing-by-another-process) – Sam H. Aug 08 '18 at 06:38

0 Answers0