Home

Awesome

gaze Build Status Build status

A globbing fs.watch wrapper built from the best parts of other fine watch libs.
Compatible with Node.js >= 4.x, Windows, macOS, and Linux.

gaze

NPM

Usage

Install the module with: npm install gaze or place into your package.json and run npm install.

const gaze = require('gaze');

// Watch all .js files/dirs in process.cwd()
gaze('**/*.js', (err, watcher) => {
  // Files have all started watching

  // Get all watched files
  const watched = watcher.watched();

  // On file changed
  watcher.on('changed', filepath => {
    console.log(filepath + ' was changed');
  });

  // On file added
  watcher.on('added', filepath => {
    console.log(filepath + ' was added');
  });

  // On file deleted
  watcher.on('deleted', filepath => {
    console.log(filepath + ' was deleted');
  });

  // On changed/added/deleted
  watcher.on('all', (event, filepath) => {
    console.log(filepath + ' was ' + event);
  });

  // Get watched files with relative paths
  const files = watcher.relative();
});

// Also accepts an array of patterns
gaze(['stylesheets/*.css', 'images/**/*.png'], () => {
  // Add more patterns later to be watched
  watcher.add(['js/*.js']);
});

Alternate Interface

const {Gaze} = require('gaze');

const gaze = new Gaze('**/*');

// Files have all started watching
gaze.on('ready', watcher => { });

// A file has been added/changed/deleted has occurred
gaze.on('all', (event, filepath) => { });

Errors

gaze('**/*', (error, watcher) => {
  if (error) {
    // Handle error if it occurred while starting up
  }
});

// Or with the alternative interface
const gaze = new Gaze();
gaze.on('error', error => {
  // Handle error here
});
gaze.add('**/*');

Minimatch / Glob

See isaacs's minimatch for more information on glob patterns.

Documentation

gaze([patterns, options, callback])

Class: gaze.Gaze

Create a Gaze object by instancing the gaze.Gaze class.

const Gaze = require('gaze').Gaze;
const gaze = new Gaze(pattern, options, callback);

Properties

Events

Methods

Similar Projects

Other great watch libraries to try are:

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

License

Copyright (c) 2018 Kyle Robinson Young
Licensed under the MIT license.