# watchdirectory

> watchdirectory ==============

Latest version **0.1.5** (published 2013-09-17) · 0 weekly downloads

## Install

```sh
npm install watchdirectory
pnpm add watchdirectory
yarn add watchdirectory
bun add watchdirectory
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2013-09-17 |
| First published | 2013-02-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | krisnye |

## Links

- npm: https://www.npmjs.com/package/watchdirectory
- npm.io page: https://npm.io/package/watchdirectory

## Recent versions

- 0.1.5 (latest) — 2013-09-17
- 0.1.4 — 2013-04-03
- 0.1.3 — 2013-02-06
- 0.1.2 — 2013-02-06
- 0.1.1 — 2013-02-06
- 0.1.0 — 2013-02-06

## README

watchdirectory
==============

Similar to node fs.watchFile but watches a directory recursively and lets you unwatch as well

## Install

<pre>
  npm install watchdirectory
</pre>

## Purpose

This module provides the ability to recursively watch a directory for changes.
Unlike similar modules, this one can unwatch as well.

#### watchdirectory.watchDirectory(root, [options,] callback)

The first argument is the directory root you want to watch. 

The options object is passed to fs.watchFile but can also be used to provide additional watchDirectory specific options:

* `'initial'` - Defaults to true.  If true then we notify the callback of files during initial directory walk.
* `'recursive'` - Defaults to true.  Controls the depth of our directory walk.
* `'include'` - Can be a function or RegExp or string.  If it's a string then that will be considered an extension to check.  Your callback will only be notified about files that match.
* `'exclude'` - Can be a function or RegExp or string.  If it's a string then that will be considered an extension to check.  Your callback will not be notified about files that match.

<pre>
  var unwatch = watchdirectory.watchDirectory('src', {filter:'.js'}, function (filename, curr, prev, change) {
    if (change == 'initial') {
      // filename found during initial pass
    }
    else if (change == 'created') {
      // filename is a new file
    }
    else if (change == 'deleted') {
      // filename was removed
    }
    else if (change == 'modified') {
      // filename was changed
    }
  });

  // later on to unwatch, just call the previously returned function
  unwatch();
</pre>

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