Skip to main content

Today's npm package: watchr

Published 1 min readMarkdown
Part of seriesPackage of the Day
Today's npm package: watchr

Today's npm package is watchr

When creating CLI utilities, if you are dealing with files, would't it be great to be able to react to the file changes.

This package would help you do the same.

Here is how you can use this package to watch for currently open directory context

const watchr = require('watchr');

const listener = (change, path, newStats, oldStats) => {
  console.log(path, change);
  // or something more useful
}

const spy = watchr.open(
  process.cwd(),
  listener,
  (err) => {
    if(err) {
      console.error(err);
      spy.close();
      return process.exit();
    }
    console.log("now watching", process.cwd());
  }
);
https://user-images.githubusercontent.com/251937/123484896-61469f00-d609-11eb-9f23-304a61599d93.mp4

Stay tuned for tomorrow's package of the Day.

About the author

  • I am developer from India currently based in Berlin, Germany.

    I am very interested in Design, though I don't design 😉 I take care of it while making my apps.

    Photography, videography and having random conversation over beer are my activities of spare time. Timelapses and hyperlapses make me wonder all the time 😊

No comments yet. Be the first to comment.

More from this blog