使用 fs.watch 但忽略 node_modules

Use fs.watch but ignore node_modules

我正在查看 fs.watch

的文档

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

如何查看当前目录下的所有文件,而忽略node_modules?

看起来不可能。只需看一下侦听器中的路径,如果它以 'node_modules'.

开头,则什么也不做

它不会对性能造成太大影响,除非您在节点 运行 时不断更新模块,这会有点奇怪。