watch vs node-watch vs chokidar vs gaze vs nodemon
ファイル監視ライブラリ
watchnode-watchchokidargazenodemon類似パッケージ:

ファイル監視ライブラリ

ファイル監視ライブラリは、ファイルシステムの変更をリアルタイムで監視し、変更があった場合に特定のアクションをトリガーするためのツールです。これにより、開発者はファイルの変更を即座に反映させたり、自動的にビルドやテストを実行したりすることができます。これらのライブラリは、開発プロセスを効率化し、手動での作業を減らすことができます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
watch884,7661,282-599年前Apache-2.0
node-watch745,43734126.1 kB83年前MIT
chokidar011,96382.1 kB354ヶ月前MIT
gaze01,155-688年前MIT
nodemon026,698219 kB91ヶ月前MIT

機能比較: watch vs node-watch vs chokidar vs gaze vs nodemon

パフォーマンス

  • watch:

    Watchは、基本的なファイル監視機能を提供しますが、パフォーマンスは他のライブラリに劣ります。

  • node-watch:

    Node-watchは、シンプルで軽量な設計で、基本的な監視機能を提供しますが、大規模なプロジェクトには向いていません。

  • chokidar:

    Chokidarは、ファイルシステムの変更を効率的に監視するために、ネイティブのファイルシステムイベントを利用します。これにより、リソースの消費を抑えつつ、高速な監視が可能です。

  • gaze:

    Gazeは、ファイルの変更を監視するために、ポーリングとファイルシステムイベントの両方を使用しますが、パフォーマンスはChokidarほど高くありません。

  • nodemon:

    Nodemonは、Node.jsアプリケーションの変更を監視し、自動的に再起動します。これにより、開発中のアプリケーションのテストが迅速に行えます。

使いやすさ

  • watch:

    Watchは、基本的な機能を提供するため、簡単に使用できますが、機能が限られています。

  • node-watch:

    Node-watchは、非常にシンプルな構文で使いやすく、すぐに導入できます。

  • chokidar:

    Chokidarは、豊富なオプションと柔軟なAPIを提供しており、複雑な監視シナリオにも対応できます。

  • gaze:

    Gazeは、シンプルなAPIを持ち、簡単に設定できるため、初心者にも扱いやすいです。

  • nodemon:

    Nodemonは、特にNode.js開発者にとって非常に使いやすく、設定が簡単です。

機能性

  • watch:

    Watchは、基本的なファイル監視機能を提供しますが、追加機能はありません。

  • node-watch:

    Node-watchは、基本的なファイル監視機能を提供し、変更があった場合にコールバックを実行します。

  • chokidar:

    Chokidarは、ファイルの追加、削除、変更を監視でき、複数のディレクトリを同時に監視することも可能です。

  • gaze:

    Gazeは、特定のファイルやディレクトリの変更を監視し、コールバックをトリガーする機能を持っています。

  • nodemon:

    Nodemonは、Node.jsアプリケーションの変更を監視し、自動的に再起動する機能に特化しています。

拡張性

  • watch:

    Watchは、基本的な機能しか提供しないため、拡張性はありません。

  • node-watch:

    Node-watchは、シンプルな設計のため、拡張性は低いですが、必要な機能は提供しています。

  • chokidar:

    Chokidarは、プラグインやカスタムイベントを追加することで、機能を拡張することが可能です。

  • gaze:

    Gazeは、シンプルな構造のため、拡張性は限られていますが、基本的なニーズには応えられます。

  • nodemon:

    Nodemonは、設定ファイルを使用してカスタマイズが可能で、拡張性があります。

コミュニティとサポート

  • watch:

    Watchは、基本的な機能を提供しますが、コミュニティは小さく、サポートは限られています。

  • node-watch:

    Node-watchは、シンプルなライブラリであり、サポートは限られていますが、基本的な使用には問題ありません。

  • chokidar:

    Chokidarは、広く使用されており、活発なコミュニティが存在します。ドキュメントも充実しています。

  • gaze:

    Gazeは、比較的小規模なコミュニティですが、基本的なサポートは得られます。

  • nodemon:

    Nodemonは、多くの開発者に支持されており、豊富なドキュメントとサポートがあります。

選び方: watch vs node-watch vs chokidar vs gaze vs nodemon

  • watch:

    Watchは、基本的なファイル監視機能を提供しますが、他のライブラリに比べて機能が限られています。シンプルな用途に適しています。

  • node-watch:

    Node-watchは、シンプルで軽量な監視ツールです。シンプルな使い方を求める開発者に向いています。

  • chokidar:

    Chokidarは、非常に効率的で高性能なファイル監視を提供します。特に、大規模なプロジェクトや多くのファイルを扱う場合に適しています。

  • gaze:

    Gazeは、シンプルなAPIを提供し、特定のファイルやディレクトリの変更を監視するのに便利です。小規模なプロジェクトや簡単なタスクに最適です。

  • nodemon:

    Nodemonは、Node.jsアプリケーションの自動再起動に特化しています。開発中のサーバーを効率的に管理したい場合に選ぶべきです。

watch のREADME

watch -- Utilities for watching file trees in node.js

Install

  npm install watch

Purpose

The intention of this module is provide tools that make managing the watching of file & directory trees easier.

watch.watchTree(root, [options,] callback)

The first argument is the directory root you want to watch.

The options object is passed to fs.watchFile but can also be used to provide two additional watchTree specific options:

  • 'ignoreDotFiles' - When true this option means that when the file tree is walked it will ignore files that being with "."
  • 'filter' - You can use this option to provide a function that returns true or false for each file and directory to decide whether or not that file/directory is included in the watcher.
  • 'interval' - Specifies the interval duration in seconds, the time period between polling for file changes.
  • 'ignoreUnreadableDir' - When true, this options means that when a file can't be read, this file is silently skipped.
  • 'ignoreNotPermitted' - When true, this options means that when a file can't be read due to permission issues, this file is silently skipped.
  • 'ignoreDirectoryPattern' - When a regex pattern is set, e.g. /node_modules/, these directories are silently skipped.

The callback takes 3 arguments. The first is the file that was modified. The second is the current stat object for that file and the third is the previous stat object.

When a file is new the previous stat object is null.

When watchTree is finished walking the tree and adding all the listeners it passes the file hash (keys are the file/directory names and the values are the current stat objects) as the first argument and null as both the previous and current stat object arguments.

  watch.watchTree('/home/mikeal', function (f, curr, prev) {
    if (typeof f == "object" && prev === null && curr === null) {
      // Finished walking the tree
    } else if (prev === null) {
      // f is a new file
    } else if (curr.nlink === 0) {
      // f was removed
    } else {
      // f was changed
    }
  })

watch.unwatchTree(root)

Unwatch a previously watched directory root using watch.watchTree.

watch.createMonitor(root, [options,] callback)

This function creates an EventEmitter that gives notifications for different changes that happen to the file and directory tree under the given root argument.

The options object is passed to watch.watchTree.

The callback receives the monitor object.

The monitor object contains a property, files, which is a hash of files and directories as keys with the current stat object as the value.

The monitor has the following events.

  • 'created' - New file has been created. Two arguments, the filename and the stat object.
  • 'removed' - A file has been moved or deleted. Two arguments, the filename and the stat object for the fd.
  • 'changed' - A file has been changed. Three arguments, the filename, the current stat object, and the previous stat object.

The monitor can be stopped using .stop (calls unwatchTree).

  var watch = require('watch')
  watch.createMonitor('/home/mikeal', function (monitor) {
    monitor.files['/home/mikeal/.zshrc'] // Stat object for my zshrc.
    monitor.on("created", function (f, stat) {
      // Handle new files
    })
    monitor.on("changed", function (f, curr, prev) {
      // Handle file changes
    })
    monitor.on("removed", function (f, stat) {
      // Handle removed files
    })
    monitor.stop(); // Stop watching
  })

CLI

This module includes a simple command line interface, which you can install with npm install watch -g.

Usage: watch <command> [...directory] [OPTIONS]

OPTIONS:
    --wait=<seconds>
        Duration, in seconds, that watching will be disabled
        after running <command>. Setting this option will
        throttle calls to <command> for the specified duration.

    --filter=<file>
        Path to a require-able .js file that exports a filter
        function to be passed to watchTreeOptions.filter.
        Path is resolved relative to process.cwd().

    --interval=<seconds>
        Specifies the interval duration in seconds, the time period between polling for file changes.

    --ignoreDotFiles, -d
        Ignores dot or hidden files in the watch [directory].

     --ignoreUnreadable, -u
        Silently ignores files that cannot be read within the
        watch [directory].

     --ignoreDirectoryPattern=<regexp>, -p
        Silently skips directories that match the regular
        expression.

It will watch the given directories (defaults to the current working directory) with watchTree and run the given command every time a file changes.

Contributing

Releasing

On the latest clean master:

npm run release:major
npm run release:minor
npm run release:patch