javascript - node.js monitoring for when a file is created -
i writing node.js program needs file name created in specific directory. doing repeated calls fs.readdir until see name of file, i'd rather more efficient. know of way this?
look @ fs.watch
(and fs.watchfile fallback) implementation, realize not perfect:
http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
caveats#
the fs.watch api not 100% consistent across platforms, , unavailable in situations. availability#
this feature depends on underlying operating system providing way notified of filesystem changes.
on linux systems, uses inotify. on bsd systems (including os x), uses kqueue. on sunos systems (including solaris , smartos), uses event ports. on windows systems, feature depends on readdirectorychangesw.
if underlying functionality not available reason, fs.watch not able function. example, watching files or directories on network file systems (nfs, smb, etc.) doesn't work reliably or @ all.
you can still use fs.watchfile, uses stat polling, slower , less reliable.
Comments
Post a Comment