JSPM

  • Created
  • Published
  • Downloads 4580
  • Score
    100M100P100Q121678F
  • License MIT

A simple file watcher for Node

Package Exports

  • nsfw

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nsfw) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-sentinel-file-watcher

Linux OS X Windows
A simple file watcher library for node.

Usage

var nsfw = require('nsfw');
return nsfw(
  'dir1',
  function(events) {
    // handle events
  })
  .then(function(watcher) {
    return watcher.start();
  })
  .then(function() {
    // we are now watching dir1 for events!
  });

// With options
return nsfw(
  'dir2',
  function(events) {
  // handles other events
  },
  {
    debounceMS: 250,
    errorCallback(errors) {
      //handle errors
    }
  })
  .then(function(watcher) {
    return watcher.start();
  })
  .then(function() {
    // we are now watching dir1 for events!
  });

Callback Argument

An array of events as they have happened in a directory, it's children, or to a file.

[
  {
    "action": 2, // nsfw.actions.MODIFIED
    "directory": "/home/nsfw/watchDir",
    "file": "file1.ext"
  },
  {
    "action": 0, // nsfw.actions.CREATED
    "directory": "/home/nsfw/watchDir",
    "file": "folder"
  },
  {
    "action": 1, // nsfw.actions.DELETED
    "directory": "home/nsfw/watchDir/testFolder",
    "file": "test.ext"
  },
  {
    "action": 3, // nsfw.actions.RENAMED
    "directory": "home/nsfw/watchDir",
    "oldFile": "oldname.ext",
    "newFile": "newname.ext"
  }
]

Event are enumerated by the nsfw.actions enumeration

nsfw.actions = {
  CREATED: 0,
  DELETED: 1,
  MODIFIED: 2,
  RENAMED: 3
};