npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

watch-fs

v0.0.7

Published

Filesystem watcher

Downloads

326

Readme

                 _____      ______        ________       
___      _______ __  /_________  /_       ___  __/_______
__ | /| / /  __ `/  __/  ___/_  __ \________  /_ __  ___/
__ |/ |/ // /_/ // /_ / /__ _  / / //_____/  __/ _(__  ) 
____/|__/ \__,_/ \__/ \___/ /_/ /_/       /_/    /____/  

Watches your files and folders and gets out of the way

##Quickstart

Watching files in a directory is as simple as instantiating a watcher and handling
events emitted when files get created, changed, or deleted.

Var Watcher = require('watchfs').Watcher;

var watcher = new Watcher({
    paths: [ 'path-to-my-dir', 'path-to-my-file', 'etc' ],
    filters: {
        includeFile: function(name) {
            return /\.js/.test(name);
        }
    });

watcher.on('create', function(name) {
    console.log('file ' + name + ' created');
});

watcher.on('change', function(name) {
    console.log('file ' + name + ' changed');
});

watcher.on('delete', function(name) {
    console.log('file ' + name + ' deleted');
});

watcher.start(function(err) {
    console.log('watcher started');
});

Options

The following options can be specified when creating a Watcher object

options.paths

This could be a string or an array containing paths to files or directories.
Any directories specified will be watched recursively unless limited by filtering.

var watcher1 = new Watcher({
    paths: '/work/my-project'
});

var watcher2 = new Watcher({
    paths: [ '/work/my-other-project', '/work/my-file' ]
});

options.filters

Filters can be used to limit which files or directories are being watched.
filters should be an object containing two functions includeDir and includeFile.
Both functions will be called when traversing the file system with the full path of each
file or directory encountered.

The example below will watch the specified folder and will recurse only one folder below

var watcher = new Watcher({
    paths: '/work/my-project',
    filters: {
        includeDir: function(fullPath) {
            return /^\/work\/my-project(\/[^/]+)?$/.test(fullPath);
        }
    }
});

In the next example we're watching only js files and we're skipping .git and node_modules folders

var watcher = new Watcher({
    paths: '/work/my-project',
    filters: {
        includeDir: function(fullPath) {
            var skip = /(\.git)|(node_modules)/.test(fullPath);
            return !skip;
        },
        includeFile: function(fullPath) {
            return /\.js/.test(fullPath);
        }
    }
});

Events

  • create fired when a file is created
  • change fired when a file is changed
  • delete fired when a file is deleted
  • any fires when any of the above events fire
watcher.on('create', function(name) {
    console.log('file ' + name + ' created');
});

watcher.on('any', function(name, type) {
    console.log('file ' + name + ' ' + type + 'd');
});

NOTES:

  • Not tested on Windows
  • Internally it uses fs.watch which could throw an EMFILE error when watching too many files. In those cases ulimit needs to be increased. Use the posix module to increase the ulimit from within a node js process.