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

hey

v0.1.2

Published

An event driven file watcher for NodeJS with some sugar

Downloads

15

Readme

Hey, an event driven file watcher for NodeJS with some sugar

Warning I: this project is in early development stage, you might not find it useful for now. It only works in Linux (2.6+) boxes (as it depends on libnotify to do most of the work).

Most of this lib is a wrapper around inotify with EventEmitter tied on.

Install from npm

$ npm install hey

Usage

	var Hey = require('hey').Hey;

	var watch = new Hey({
		path : '/path/to/something',
		recursive : true | false [,
		mask : Hey.FLAGS.DELETE | Hey.FLAGS... ]
	});

	watch.on('create', function(path, type, mask) {
		// do what do you want cause a pirate is free ...
	});

	watch.on('EOB', function() {
		console.log('sorry mate, you\'re watching too many files for now');
	});

API

Constructor

Hey constructor takes an object as parameter, and it contains the following keys:

  • path : the path to watch (required, obviously);
  • recursive : in the case the path you choose is a folder, you can choose to watch it recursively. Optional, default not set;
  • mask : the mask to listen to. Ex. if you want just to watch for new files, you use only Hey.FLAGS.CREATE as mask. All available masks (for Hey, not libnotify) are listed in this document; Optional, default to Hey.FLAGS.MODIFY | Hey.FLAGS.CREATE | Hey.FLAGS.DELETE | Hey.FLAGS.SELF_DELETE | Hey.FLAGS.MOVE | Hey.FLAGS.SELF_MOVE;

Warning II: activating recursive in a folder, you may run out of buffer (as it supports 1024 listeners). We do not plan to change this now as it required, on Linux, changing the ulimit fopen size and the source code of inotify.

Available events

The following events are available for use (but, most of them only work with folders):

  • EOB : fired when all available listeners are taken; perhaps you're watching too many files?
  • any : fired when any path event occurs (except EOB);
  • access : fired when a file is accessed;
  • modify : fired when a file is modified;
  • open : fired when a file is opened;
  • close : fired when a file is closed;
  • metadata : fired when the path attributes are modified;
  • create : fired when a path is created;
  • delete : fired when a path is deleted;
  • self delete : fired when the path from constructor is deleted;
  • self move : fired when the path from constructor is moved;
  • move : fired when a path is moved;
  • ignore : fired when an event is ignored (this event could happen if you use your own mask);
  • unknown : fired when an unknown event happens to a path (not really unknown, but not relevant to the moment IMHO).

Mask flags

  • Hey.FLAGS.ACCESS
  • Hey.FLAGS.MODIFY
  • Hey.FLAGS.OPEN
  • Hey.FLAGS.CLOSE
  • Hey.FLAGS.METADATA
  • Hey.FLAGS.CREATE
  • Hey.FLAGS.DELETE
  • Hey.FLAGS.SELF_DELETE
  • Hey.FLAGS.SELF_MOVE
  • Hey.FLAGS.MOVE
  • Hey.FLAGS.IGNORE

Future

Our plan is to support all platforms in the future, as Node's fs.watch() evolves (seriously, do this kind of work on what it is now would be insane).

TODO

  • better documentation of the source code;
  • a real document page, examples, and so on;
  • tests!
  • ~~jsHint standards~~ we don't like code standards.

License

Copyright (C) 2012 Humantech

Distributed under the MIT License, the same as NodeJS.

Read this if you're in doubt.

References