# directory-watcher

> A directory watcher

Latest version **2.0.3** (published 2018-08-31) · 0 weekly downloads

## Install

```sh
npm install directory-watcher
pnpm add directory-watcher
yarn add directory-watcher
bun add directory-watcher
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2018-08-31 |
| First published | 2012-12-31 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kessler, yaniv |

## Links

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

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## Recent versions

- 2.0.3 (latest) — 2018-08-31
- 2.0.2 — 2014-06-28
- 2.0.0 — 2014-06-04
- 1.0.1 — 2013-01-01
- 1.0.0 — 2012-12-31

## README

DirectoryWatcher
================

A directory watcher that keeps an in memory list of the files in the directory, perfoming diffs on them when events arise from the underlying 
[FSWatcher](http://nodejs.org/api/fs.html#fs_class_fs_fswatcher), which doesn't always reports back the files that are related to an event.

The API also provides "nicer" events using the [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter) API: "change", "add", "delete". (currently "change" doesn't function properly *if* the underlying watcher does not return the changed filename)

### Install ###

```
	npm install directory-watcher
```


### create a watcher using [FSWatcher](http://nodejs.org/api/fs.html#fs_class_fs_fswatcher) ###

```
var DirectoryWatcher = require('directory-watcher');

DirectoryWatcher.create('/path/to/somewhere', function(err, watcher) {
	watcher.once('change', function(files) {
		console.log('will fire once');		
	});

	watcher.on('delete', function(files) {
		console.log('%s deleted', files);
	});

	watcher.on('add', function(files) {
		console.log('%s added', files);
	});
});

```


### using without [FSWatcher](http://nodejs.org/api/fs.html#fs_class_fs_fswatcher) or with external FSWatcher (untested) ###

```
var DirectoryWatcher = require('directory-watcher');

DirectoryWatcher.createEx('/path/to/somewhere', function(err, watcher) {
	var onFileEvent = watcher.listener();
	onFileEvent('rename', undefined);
});

```

or

```
var DirectoryWatcher = require('directory-watcher');
var fs = require('fs');

DirectoryWatcher.createEx('/path/to/somewhere', function(err, watcher) {
	fs.watch(path, watcher.listener(), { persistent: false });
});

```
note that watcher.kill() will only clear the internal files cache in this instance

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