I'm using the Node.js package "chokidar" for this use case:
add
events, for when files are atomically moved into the watched directory (they're moved from another directory on the same filesystem once all changes are done)...
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
add
events for new files only?chokidar.watch("/my-watched-dir", {
ignoreInitial: true,
})
.on('add', (filepath) => {...}
I've also tried setting the depth
option to 0 and 1 too.
The memory usage climbs very high as soon as the app starts (even before the 1st new file appears triggering the add
event for the first time).
And there's no problem when the number of pre-existing files is smaller, so it's not an issue related to through-put of new files after the app starts.
As far as I know, libraries like chokidar on Linux platforms will directly use fs.watch and fs.watchFile provided by Node.js.
To be cross-platform, these two APIs always listen for all events related to paths, so the answer is that you can't use chokidar for your purposes.
If you wish to use less memory, either poll manually or use a native Linux module that has direct access to inotify.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.