# fs-watch-tree

> Recursively watch directories for changes

Latest version **0.2.5** (published 2014-02-28) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install fs-watch-tree
pnpm add fs-watch-tree
yarn add fs-watch-tree
bun add fs-watch-tree
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2014-02-28 |
| First published | 2012-04-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Magnar Sveen |
| Maintainers | cjohansen, augustl, dwittner |

## Links

- npm: https://www.npmjs.com/package/fs-watch-tree
- Repository: https://github.com/busterjs/fs-watch-tree
- Homepage: http://busterjs.org/doc/fs-watch-tree
- Issues: https://github.com/busterjs/fs-watch-tree/issues
- npm.io page: https://npm.io/package/fs-watch-tree

## Dependencies (2)

- [when](https://npm.io/package/when.md) https://github.com/cujojs/when/tarball/1.3.0
- [minimatch](https://npm.io/package/minimatch.md) ~0.2

## Recent versions

- 0.2.5 (latest) — 2014-02-28
- 0.2.4 — 2014-02-28
- 0.2.3 — 2014-02-27
- 0.2.2 — 2012-07-09
- 0.2.1 — 2012-06-20
- 0.2.0 — 2012-04-28
- 0.1.0 — 2012-04-17

## README

# fs-watch-tree #

**Please note!** This package is outdated and not actively maintained. I would suggest looking at http://github.com/shama/gaze or https://github.com/paulmillr/chokidar.

-----------------------------

**fs-watch-tree** is a small tool to watch directories for changes recursively.
It uses
[fs-watch](http://nodejs.org/docs/latest/api/fs.html#fs_fs_watch_filename_options_listener)
to watch for changes, thus should work on most platforms.

## Synopsis ##

    var watchTree = require("fs-watch-tree").watchTree;

    var watch = watchTree("/home/christian", function (event) {
        // See description of event below
    });

    watch.end(); // Release watch

    watch = watchTree("/home/christian", {
        exclude: ["node_modules", "~", "#", /^\./]
    }, function (event) {
        // Respond to change
    });

## `watchTree(dir, callback)` ##

Watches directory `dir` recursively for changes.

The callback is called with an `event` object. The event is described below.

## `watchTree(dir, options, callback)` ##

Watch a directory recursively, with some specific options. Currently, you can
only specify a single option:

    { exclude: [] }

The `exclude` array specifies file patterns to exclude from watches. If a
pattern matches a directory, `watch-tree` will not recurse into it. If it
matches a file, changes to that file will not trigger an event.

The excludes can be either strings or regular expressions, but are always
treated as regular expressions. That means that

    { exclude: [".git", "node_modules"] }

Will be treated the same way as:

    { exclude: [new RegExp(".git"), new RegExp("node_modules")] }

If you only want to exclude specific files, be sure to provide full
paths. `watch-tree` does not expand paths, it will resolve all paths relative to
the original directory. So this:

    watchFile(".git", function (event) { /* ... *) });

Will watch (and consider excludes for) directories like `.git/branches`. And
this:

    watchFile("/home/christian/projects/watch-tree/.git", function (event) {});

Will watch (and consider excludes for) directories like
`/home/christian/projects/watch-tree/.git`.

## `event` ##

The event object has the following properties:

### `name` ###

The full (relative) path to the file/directory that changed.

### `isDirectory()` ###

Returns true if the cause of the change was a directory. In some cases,
e.g. when the directory was deleted, it's not possible to know if the
source was a directory. In that case, this method returns false.

### `isMkdir()` ###

Returns true if the cause of the event was a newly created directory.

### `isDelete()` ###

Returns true if the cause of the event was a deleted file/directory.

### `isModify()` ###

Returns true if the cause of the event was a modified file/directory.

---
_Source: https://npm.io/package/fs-watch-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
