Skip to content

Latest commit

 

History

History
55 lines (32 loc) · 1.34 KB

readme.md

File metadata and controls

55 lines (32 loc) · 1.34 KB

File Pollex

A tiny hybrid filesystem watcher for a single file.

This uses a combination of native filesystem watching and polling to be simultaneously reliable, responsive, and tiny.

For more complicated use cases than just watching a single file check out pollex and watcher.

Install

npm install --save file-pollex

Usage

import watchFile from 'file-pollex';

// Let's define some options

const watchOptions = {
  ignoreInitial: true, // Ignore the initial "add" event that may be emitted while the file path is being polled for the first time
  ignoreReady: true, // Ignore the "ready" event, useful in combination with "ignoreInitial: true" to only get notified about actual changes
  pollingInterval: 1000 // Poll the file path on this interval, to more reliably detect "add" and "unlink" events
};

// Let's listen for events

watch ( 'foo.txt', event => {

  if ( event === 'add' ) {

    // The file got added

  } else if ( event === 'change' ) {

    // The file got changed

  } else if ( event === 'ready' ) {

    // The initial polling has been done and the eventual initial "add" event has been emitted

  } else if ( event === 'unlink' ) {

    // The file got deleted

  }

}, watchOptions );

License

MIT © Fabio Spampinato