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

tiny-watcher

v0.1.2

Published

A tiny wrapper around fs.watch for added, removed and changed events

Downloads

10

Readme

tiny-watcher

There is no such thing as fs.watch and this is a wrapper around it. Another one. Yep, there are lots of wrappers and I tried a couple for my project but found that they were all buggy in their own idiosyncratic ways. I needed one that was buggy in a specific way, so I coded up tiny-wrapper.

Example

var tiny = require('../.')
  , fs = require('fs')
  , rimraf = require('rimraf')
  , path = require('path')


var somedir = "somedir"

fs.mkdirSync(somedir)
var watcher = tiny(somedir, ["test", "total"])

watcher.on("added", function (file) {
  console.log("EXAMPLE: added", file)
})

watcher.on("removed", function (file) {
  console.log("EXAMPLE: removed", file)
})

watcher.on("changed", function (file) {
  console.log("EXAMPLE: changed", file)
})

// ADD TEST
fs.writeFileSync(path.join(somedir, "test"), "data")
// REMOVE TEST
fs.unlinkSync(path.join(somedir, "test"))
// ADD TOTAL
fs.writeFileSync(path.join(somedir, "total"), "data")
// CHANGE TOTAL
fs.writeFileSync(path.join(somedir, "total"), "new data")
// ADD TONNES (NOT IN SPECIFIED FILE LIST)
fs.writeFileSync(path.join(somedir, "tonnes"), "data")

/*
 * Setting watcher kill should stop the remove event
 * when total is removed with rimraf
 */
setTimeout( function () {

  watcher.close()
  rimraf(somedir, function (err) {

    if (err) throw err

    process.exit()

  })
}, 1000)

which produces

EXAMPLE: added test
EXAMPLE: removed test
EXAMPLE: added total
EXAMPLE: changed total
EXAMPLE: added test
EXAMPLE: removed test

API

tiny

The main object is a function that produces watchers for a specific directory an optional set of files.

var watcher = tiny("path/to/dir" [, ["list", "of", "files"]])

watcher.on

Three events, added, removed and changed are supported. The callback returns the filename.

watcher.kill

Calls the base fs method watcher.close()

INSTALL

npm install tiny-watcher

LICENSE

MIT