Incremental utilities for NodeJS File System API.


Incremental utilities for NodeJS File System API.


  • Linux
  • MacOSX
  • Windows


Setting up

FS Watcher

Provides the ability to watch an entire tree of dirs and files.

fsu = require 'fs-util'
watcher = fsu.watch [desired_path][regex_pattern][recursive_notifications]


The path to the dir or file you wanna watch.


The regex to filter only the files you wanna watch.


If true notifications will be fired for all files. If you delete a dir that has many sub dirs and files, an unwatch and delete events will be dispatched for all the children dirs and files as well.

If false, only one event will be dispatched for the dir that was actually deleted. It can save you an overhead of events popping up when a dir with big ammount of subdirs and files is deleted.

  • watch
  • unwatch
  • create
  • change
  • delete

Bellow is a very basic usage example that can be found in the examples folder.

fsu = require 'fs-util'
watcher = fsu.watch 'desired/path'/.coffee$/mtrue
watcher.on 'watch'(f)-> console.log 'WATCHED ' + [f.typef.location]
watcher.on 'unwatch'(f)-> console.log 'UNWATCHED ' + [f.typef.location]
watcher.on 'create'(f)-> console.log 'CREATED ' + [f.typef.location]
watcher.on 'change'(f)-> console.log 'CHANGED ' + [f.typef.location]
watcher.on 'delete'(f)-> console.log 'DELETED ' + [f.typef.location]

All callbacks receives only one argument which is the related [f]ile to the event.

It has the following properties:


Fullpath location of the item.


Item type, can be dir or file.


Last stat of the file, it's an instance of fs.Stats.


Current stat of the file, it's an instance of fs.Stats.


The complete tree of subitems (files and dirs) under that point.

  • Applies only when f.type is dir

Besides all the Event Emiter inherited methods, the watcher class has one more:


When called, this method will forcely close all persistent watcher's process and removes all previously added listeners. Every file and folder is unwatched, events will pop normally for them, and after that the instance becomes useless.

FS Tools

Provides functionalities such as rm_rf, cp_r, mkdir_p, find and ls.

fsu = require 'fs-util'
fsu.mkdirp [dir_path]
fsu.touch [file_path][encoding='utf-8']
fsu.copy [from_path][to_path]
fsu.find [path][regex_pattern][include_dirs]
fsu.ls [path]
fsu.rm_rm [path]


Absolute or relative paths are accepted, you take care of your things.


The file encoding when touching it.


Your search pattern, i.e. /.coffee$/m.


When true will include the dirs in the search, otherwise only files.


Remembers that you need to install fs-util locally in order to use it as a LIB. You will need to require 'fs-util in you script, there's no reason to install it globally with -g, fs-util won't work directly in the command line.

At least for now.

npm install fs-util

In order to contribute you will need to fork, clone and initialize the env.

git clone git@github.com:[username]/fs-util
cd fs-util && npm install

Build the src/*.coffee files to lib/*.js.

make build

Continuously building in watch mode.

make watch

Running tests suite.

make test