Watches a path, whether the path is a file or a directory containing many files. Doesn't care whether the path exists or not, whether it disappears and reappears, etc.

constructor

Spy ( ) {

Arguments

| String path

The path to a file or directory to watch.

optional
| surveil:Options options

Override default options.

Events

add

A child file has been added to the target directory. Also emitted with no filename argument when the target path appears, whether it is a directory or file. You can use the isFile property if you need to know more about the target path.

optional
| String filename

The local name of the file that was added. When omitted, indicates that the target path itself has appeared.

change

A child file has been modified within the target directory. This event is batched with a configurable timeout. When the target path is a file, changes to the target file cause change to be emitted with no filename argument.

optional
| String filename

The local name of the file that has changed. When omitted, indicates that the target path is a file and it has changed.

error

If the target path suddenly becomes unwatchable due to a permissions issue or serious filesystem error, the offending Error is emitted. When the ready event comes with an Error, an error event is also emitted immediately after.

| Error err

The underlying Error message, produced by the fs module.

ready

The initial readiness state has been reached. Emitted after one tick when a file or missing path is targeted. If a directory is found, initial readiness is delayed until watches have been established on the directory's children.

| Error err

If a permissions problem or serious filesystem error prevents watching the target path, the offending Error instance as produced by the fs module is passed to ready. An immediate error event will follow.

remove

A child file has been removed from the target directory. Also emitted with no filename argument when the target path disappears, whether it was a directory or file.

optional
| String filename

The local name of the file that was removed. When omitted, indicates that the target path itself has disappeared.

Member Properties

| Boolean exists

Whether the watched path currently exists. This value is considered up-to-date during event listener execution.

| Boolean isFile

Whether the watched path is currently a file rather than a directory. This value is considered up-to-date during event listener execution.

| Boolean ready

Whether the initial readiness state has been reached. Set true after one tick when a file or missing path is targeted. If a directory is found, initial readiness is delayed until watches have been established on the directory's children.

Methods

close ( ) {

Terminates all file watching activities and closes the native file watches. No more events will be emitted. This Spy cannot be recovered once closed.