Nodejs listens to all files in the directory

  node.js, question

There is a project that wants to use nodejs to monitor all files in the folder directory.

When files are added to the folder directory, a script is executed

How to monitor whether there are new files generated, not file modifications, but new files added

I can’t help it.

Young man, you need

npm install chokidar --save

Why?

Node.js fs.watch:

  • File names will no longer be displayed on os x.

  • The event will not be triggered when you edit files with an editor in OS X.

  • Two consecutive events are often triggered

  • There is no good interface to recursion files

  • Wait

Node.js fs.watchFile:

  • They often hang up when handling incidents.

  • Unable to recursively file

  • Excessive occupancy rate in Central Processor

Let’s look at the data again.
clipboard.png

So useChokidarIt’s a good idea.