v0.1.31
Watch for changes on filename. The callback listener will be called each time the file is accessed.
A path to a file or directory. If a URL is provided, it must use the file: protocol.
The callback listener will be called each time the file is accessed.
Generated using TypeDoc
Watch for changes on
filename. The callbacklistenerwill be called each time the file is accessed.The
optionsargument may be omitted. If provided, it should be an object. Theoptionsobject may contain a boolean namedpersistentthat indicates whether the process should continue to run as long as files are being watched. Theoptionsobject may specify anintervalproperty indicating how often the target should be polled in milliseconds.The
listenergets two arguments the current stat object and the previous stat object:These stat objects are instances of
fs.Stat. If thebigintoption istrue, the numeric values in these objects are specified asBigInts.To be notified when the file was modified, not just accessed, it is necessary to compare
curr.mtimeMsandprev.mtimeMs.When an
fs.watchFileoperation results in anENOENTerror, it will invoke the listener once, with all the fields zeroed (or, for dates, the Unix Epoch). If the file is created later on, the listener will be called again, with the latest stat objects. This is a change in functionality since v0.10.Using watch is more efficient than
fs.watchFileandfs.unwatchFile.fs.watchshould be used instead offs.watchFileandfs.unwatchFilewhen possible.When a file being watched by
fs.watchFile()disappears and reappears, then the contents ofpreviousin the second callback event (the file's reappearance) will be the same as the contents ofpreviousin the first callback event (its disappearance).This happens when: