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

watchboy

v0.4.3

Published

watchboy

Downloads

56,747

Readme

watchboy

watchboy logo

travis npm-downloads npm-version dm-david

Watch files and directories for changes. Fast. No hassle. No native dependencies. Works the same way on Windows, Linux, and MacOS. Low memory usage. Shows you a picture of a dog. It's everything you've ever wanted in a module!

Install

npm install watchboy

Example

const watchboy = require('watchboy');

// watch all files in the current directory, except node modules and dotfiles
const watcher = watchboy(['**/*', '!node_modules/**', '!.*']);

watcher.on('add', ({ path }) => console.log('add:', path));
watcher.on('addDir', ({ path }) => console.log('addDir:', path));
watcher.on('change', ({ path }) => console.log('change:', path));
watcher.on('unlink', ({ path }) => console.log('unlink:', path));
watcher.on('unlinkDir', ({ path }) => console.log('unlinkDir:', path));

watcher.on('ready', () => console.log('all initial files and directories found'));
watcher.on('error', err => console.error('watcher error:', err));

// stop all watching
// watcher can no longer be used and it will no longer fire any events
watcher.close();

API

watchboy(pattern, [options])EventEmitter

Watchboy is exposed as a function which returns an event emitter. It takes the following parameters:

  • pattern (string|Array<string>): A glob string or array of glob strings to watch, including positive and negative patterns. Directories are also expanded.
  • [options] (Object): An optional options object, which contains the following properties:
    • [cwd = process.cwd()] (string): The root directory from which to glob.
    • [persistent = true] (boolean): Whether the process should continue to run as long as files are being watched.

The following events are available on the watcher:

.on('add', ({ path }) => {})EventEmitter

Indicates that a new file was added. There is a single argument for this event, which has a path property containing the absolute path for the file that was added.

.on('addDir', ({ path }) => {})EventEmitter

Indicates that a new directory was added. There is a single argument for this event, which has a path property containing the absolute path for the directory that was added. Files in this new directory will also be watched according to the provided patterns.

.on('change', ({ path }) => {})EventEmitter

Indicates that a file has changed. There is a single argument for this event, which has a path property containing the absolute path for the file that has changed.

.on('unlink', ({ path }) => {})EventEmitter

Indicates that a watched file no longer exists. There is a single argument for this event, which has a path property containing the absolute path for the file that no longer exists.

.on('unlinkDir', ({ path }) => {})EventEmitter

Indicates that a watched directory no longer exists. There is a single argument for this event, which has a path property containing the absolute path for the directory that no longer exists.

.on('ready', () => {})EventEmitter

Indicates that all initial files and directories have been discovered. This even has no arguments. Note that new add and addDir events may fire after this, as new files and directories that match the patterns are created.

.on('error', (err) => {})EventEmitter

Indicates that an error has occurred. You must handle this event so that your application does not crash. This error has a single argument: an error which indicates what happened. Aside from standard error properties, there is an additional path property indicating the absolute path of the file or directory which triggered the error.

.close()

Stop watching all files. After this method is called, the watcher can no longer be used and no more events will fire.

Performance

Check out this benchmark comparing watchboy to popular alternatives. Spoiler: it fares really well.