1

I am looking at the docs for fs.watch

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

How can I watch all files in the current directory, but ignore node_modules?

  • Why are you not using [chokidar](https://www.npmjs.com/package/chokidar) ? It have a `ignored` option and it is alot better than the native `fs.watch` module. **FYI** [How efficient is _Chokidar_ Node.js](https://stackoverflow.com/questions/19343584/how-efficient-is-chokidar-node-js) – Dany Gagnon Jan 02 '18 at 02:53

1 Answers1

2

Doesn't look like it's possible. Just take a look at the path in the listener and do nothing if it starts with 'node_modules'.

It can't be that much of a performance hit, unless you're constantly updating modules while node is running, which would be a little strange.

Jim B.
  • 4,512
  • 3
  • 25
  • 53
  • yeah, another weird thing, it doesn't seem to watch non-.js files –  Jan 01 '18 at 23:57
  • ahh, I know why, I need to use recursive setting for it to watch everything –  Jan 02 '18 at 00:00