Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

watch

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watch

Utilities for watching file trees.

  • 0.18.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is watch?

The 'watch' npm package is a utility that allows you to monitor files and directories for changes. It can be used to trigger actions when files are modified, added, or deleted, making it useful for tasks such as automated testing, live reloading, and continuous integration.

What are watch's main functionalities?

Watch a single file

This feature allows you to watch a single file for changes. When the file is modified, the callback function is triggered.

const watch = require('watch');

watch.watchFile('/path/to/file', function (curr, prev) {
  console.log('File changed');
});

Watch a directory

This feature allows you to watch a directory and its subdirectories for changes. The callback function is triggered when files are added, removed, or modified.

const watch = require('watch');

watch.watchTree('/path/to/dir', function (f, curr, prev) {
  if (typeof f == 'object' && prev === null && curr === null) {
    console.log('Finished walking the tree');
  } else if (prev === null) {
    console.log('New file added: ' + f);
  } else if (curr.nlink === 0) {
    console.log('File removed: ' + f);
  } else {
    console.log('File changed: ' + f);
  }
});

Ignore specific files or directories

This feature allows you to ignore specific files or directories while watching. In this example, dot files and the 'node_modules' directory are ignored.

const watch = require('watch');

watch.watchTree('/path/to/dir', {
  ignoreDotFiles: true,
  filter: function (f, stat) {
    return !/node_modules/.test(f);
  }
}, function (f, curr, prev) {
  console.log('File changed: ' + f);
});

Other packages similar to watch

Keywords

FAQs

Package last updated on 29 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc