node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »



Witness v. 3. to bear witness to; testify to; give or afford evidence of.


The witness is an intelligent file content cache that keeps track ( optionally on a per-caller basis) of the state of a file.


Witness may be installed using Node and npm.

npm install witness


Witness can be used on a individual persistent basis or as a listener.

// For this example assume we have three files layed out as follows: 
//  - src/ 
//  - src/ 
//  - src/ 
// Require the witness and initialize it. 
Witness = require('witness');
audtior = new Witness(/* The persistent cache file can be passed in here;
                         defaults to './.witness-cache' */);
// Checking the state of some files. 
witness.state('src/');   // == 'added' 
witness.state('src/');   // == 'added' 
witness.state('src/'); // == 'added' 
witness.state('src/');   // == 'ready' 
// Now assume we have modified the content of one of 'src/'. 
witness.state('src/');   // == 'changed' 
witness.state('src/');   // == 'ready' 
// To allow a single process to maintain its event queue independent of another 
// in a persistent way, one may specify a context as the second argument 
// to `witness::state`. 
witness.state('src/', 'apple');   // == 'added' 
witness.state('src/', 'apple');   // == 'ready' 
witness.state('src/', 'orange');  // == 'added' 
witness.state('src/', 'orange');  // == 'ready' 
// Now if we assume we modified the content again. Notice how 'apple' and 
// 'orange' only get notified about the changed event once. 
witness.state('src/', 'apple');   // == 'changed' 
witness.state('src/', 'orange');  // == 'changed' 
witness.state('src/', 'apple');   // == 'ready' 
witness.state('src/', 'orange');  // == 'ready' 
// This is to be used at the end of process; this writes the in-memory 
// cache to a persistent file.;


Unless otherwise noted, all files contained within this project are liensed under the MIT opensource license. See the included file LICENSE or visit for more information.