T
T
TheGhost9022018-10-05 13:02:49
Node.js
TheGhost902, 2018-10-05 13:02:49

How to make fs watch in node.js watch files in subfolders?

node.js documentation has this example:

fs.watch('./', { encoding: 'utf8' }, (eventType, filename) => {
  if (filename) {
    console.log(filename);
  }
});

it watches the files in the "./" folder, but this folder contains, for example, the "somedir" folder, and if you change the files in it, the fs.watch module does not work. Please tell me how to solve this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-10-05
@TheGhost902

https://nodejs.org/docs/latest/api/fs.html#fs_fs_w...

fs.watch('./', { encoding: 'utf8', recursive: true }, (eventType, filename) => {
  if (filename) {
    console.log(filename);
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question