{"description":"A wrapper and enhancements for fs.watch","license":"MIT","name":"node-watch","repository":{"url":"git://github.com/yuanchuan/node-watch.git","type":"git"},"keywords":["fs.watch","watch","watchfile"],"version":"0.6.4","bugs":{"url":"https://github.com/yuanchuan/node-watch/issues"},"url":"https://github.com/yuanchuan/node-watch","author":{"name":"yuanchuan","email":"yuanchuan23@gmail.com","url":"http://yuanchuan.name"},"main":"./lib/watch","types":"./lib/watch.d.ts","homepage":"https://github.com/yuanchuan/node-watch#readme","scripts":{"test":"mocha test/test.js --exit --slow 500"},"engines":{"node":">=6"},"devDependencies":{"fs-extra":"^7.0.1","mocha":"^5.2.0"},"gitHead":"d40487825de9efdb8b1337256dd267741911f129","_id":"node-watch@0.6.4","_nodeVersion":"11.7.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-cI6CHzivIFESe8djiK3Wh90CtWQBxLwMem8x8S+2GSvCvFgoMuOKVlfJtQ/2v3Afg3wOnHl/+tXotEs8z5vOrg==","shasum":"50e564046eb7be15151c25f9c5aac4b5f495c291","tarball":"http://registry-npm.ywwl.com/node-watch/download/node-watch-0.6.4.tgz","fileCount":14,"unpackedSize":52600,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJerAAtCRA9TVsSAnZWagAAEUUP/jNyckEIouf7Rhsn+eJb\nExNBxu0wav+hBmJ9o2fsJVVk81jfoJNPlRcKLLRwsTau+G5m0ELfKR3HthmX\nNHnOcr2eYVeo9s21vWNRHj6ljYrUiliWa4rfmOdwF+h+qnmOEK9O7UINz5gl\n+r8c8v1tDLomBbtP3Sa2/q+Tjs9I5DIImfpKBKyIHK4S8atig51AMpj0i9Mj\n7jEgcaOAGEFii/9B7jXkLmdNohhKtTojjNMIfiRRwTsJ7JmMdqjw1VpCYbXa\n3O3hzUxbWyGbboogMJXiZEyqfLNgDI1hs7jlH1qwmJVVw3fmqfRi+GlXzF6K\nWc1Aru3rrXca0jd1mWQl80yJJtHcsrbwDv17TgdiAU1fbd477kMPUcomXM6D\ngN3VDvEiFAJR0D1EyTjRLIcqaqkddiT91H4V5bEqIOvQKn0IqfShPJTLrfrz\nbFionkFB+w923vVqpARbr3h17ywKfjfLYcXj9unrzzxxks1aEhDeaj6UQN0C\nW22DWegH/B0Hx4x9G48gywssRRzxfgNdBgTcklM8q0JS+OFAhDY9/pfFaZd2\npcHCSY8VQmfpQzM411yEB+T5F5Ie6hXgQh8k9eiMUOrgoqtgSVnb7nDyy2kN\nRhcuwAZtuCxkvLuyY4PeJCmlDgavzmdkIUawV8LdUCK96C/AUJTWwTS/m6DZ\n3UIk\r\n=jrAA\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICV9OEj7exFLVz4wnr+W+qv5i9lUJdSJG6YQt61a0As/AiB9e+CR23y8vwFgX/H70i+a5qOjqJ48Dse+wrYnbXek7g=="}],"size":13571,"noattachment":false,"key":"/node-watch/-/node-watch-0.6.4.tgz"},"maintainers":[{"name":"yuanchuan","email":"yuanchuan23@gmail.com"}],"_npmUser":{"name":"yuanchuan","email":"yuanchuan23@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-watch_0.6.4_1588330540762_0.671795668994638"},"_hasShrinkwrap":false,"readme":"# node-watch [![Status](https://github.com/yuanchuan/node-watch/actions/workflows/ci.yml/badge.svg)](https://github.com/yuanchuan/node-watch/actions/workflows/ci.yml/badge.svg)\n\nA wrapper and enhancements for [fs.watch](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener).\n\n[![NPM](https://nodei.co/npm/node-watch.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/node-watch.png/)\n\n\n## Installation\n\n```bash\nnpm install node-watch\n```\n\n## Example\n\n```js\nvar watch = require('node-watch');\n\nwatch('file_or_dir', { recursive: true }, function(evt, name) {\n  console.log('%s changed.', name);\n});\n```\n\nNow it's fast to watch **deep** directories on macOS and Windows, since the `recursive` option is natively supported except on Linux.\n\n```js\n// watch the whole disk\nwatch('/', { recursive: true }, console.log);\n```\n\n\n## Why?\n\n* Some editors will generate temporary files which will cause the callback function to be triggered multiple times.\n* The callback function will only be triggered once on watching a single file.\n* <del>Missing an option to watch a directory recursively.</del>\n* Recursive watch is not supported on Linux or in older versions of nodejs.\n* Keep it simple, stupid.\n\n\n## Options\n\nThe usage and options of `node-watch` are compatible with [fs.watch](https://nodejs.org/dist/latest-v7.x/docs/api/fs.html#fs_fs_watch_filename_options_listener).\n* `persistent: Boolean` (default **true**)\n* `recursive: Boolean` (default **false**)\n* `encoding: String` (default **'utf8'**)\n\n**Extra options**\n\n* `filter: RegExp | Function`\n\n   Return that matches the filter expression.\n\n    ```js\n    // filter with regular expression\n    watch('./', { filter: /\\.json$/ });\n\n    // filter with custom function\n    watch('./', { filter: f => !/node_modules/.test(f) });\n\n    ```\n\n   Each file and directory will be passed to the filter to determine whether\n   it will then be passed to the callback function. Like `Array.filter` does in `JavaScript`.\n   There are three kinds of return values for filter function:\n\n     * **`true`**: Will be passed to callback.\n     * **`false`**: Will not be passed to callback.\n     * **`skip`**: Same with `false`, and skip to watch all its subdirectories.\n\n   On Linux, where the `recursive` option is not natively supported,\n   it is more efficient to skip ignored directories by returning the `skip` flag:\n\n    ```js\n    watch('./', {\n      recursive: true,\n      filter(f, skip) {\n        // skip node_modules\n        if (/\\/node_modules/.test(f)) return skip;\n        // skip .git folder\n        if (/\\.git/.test(f)) return skip;\n        // only watch for js files\n        return /\\.js$/.test(f);\n      }\n    });\n\n    ```\n\n    If you prefer glob patterns you can use [minimatch](https://www.npmjs.com/package/minimatch) or [picomatch](https://www.npmjs.com/package/picomatch)\n    together with filter:\n\n     ```js\n     const pm = require('picomatch');\n     let isMatch = pm('*.js');\n\n     watch('./', {\n       filter: f => isMatch(f)\n     });\n     ```\n\n* `delay: Number` (in ms, default **200**)\n\n   Delay time of the callback function.\n\n    ```js\n    // log after 5 seconds\n    watch('./', { delay: 5000 }, console.log);\n    ```\n\n## Events\n\nThe events provided by the callback function is either `update` or `remove`, which is less confusing to `fs.watch`'s `rename` or `change`.\n\n```js\nwatch('./', function(evt, name) {\n\n  if (evt == 'update') {\n    // on create or modify\n  }\n\n  if (evt == 'remove') {\n    // on delete\n  }\n\n});\n```\n\n\n## Watcher object\n\nThe watch function returns a [fs.FSWatcher](https://nodejs.org/api/fs.html#fs_class_fs_fswatcher) like object as the same as `fs.watch` (>= v0.4.0).\n\n#### Watcher events\n\n```js\nlet watcher = watch('./', { recursive: true });\n\nwatcher.on('change', function(evt, name) {\n  // callback\n});\n\nwatcher.on('error', function(err) {\n  // handle error\n});\n\nwatcher.on('ready', function() {\n  // the watcher is ready to respond to changes\n});\n```\n\n#### Close\n\n```js\n// close\nwatcher.close();\n\n// is closed?\nwatcher.isClosed()\n```\n\n#### List of methods\n\n* `.on`\n* `.once`\n* `.emit`\n* `.close`\n* `.listeners`\n* `.setMaxListeners`\n* `.getMaxListeners`\n\n##### Extra methods\n* `.isClosed` detect if the watcher is closed\n* `.getWatchedPaths` get all the watched paths\n\n\n## Known issues\n\n**Windows, node < v4.2.5**\n\n  * Failed to detect `remove` event\n  * Failed to get deleted filename or directory name\n\n**MacOS, node 0.10.x**\n  * Will emit double event if the directory name is of one single character.\n\n\n## Misc\n\n#### 1. Watch multiple files or directories in one place\n```js\nwatch(['file1', 'file2'], console.log);\n```\n\n#### 2. Customize watch command line tool\n```js\n#!/usr/bin/env node\n\n// https://github.com/nodejs/node-v0.x-archive/issues/3211\nrequire('epipebomb')();\n\nlet watcher = require('node-watch')(\n  process.argv[2] || './', { recursive: true }, console.log\n);\n\nprocess.on('SIGINT', watcher.close);\n```\nMonitoring chrome from disk:\n```bash\n$ watch / | grep -i chrome\n```\n\n#### 3. Got ENOSPC error?\n\nIf you get ENOSPC error, but you actually have free disk space - it means that your OS watcher limit is too low and you probably want to recursively watch a big tree of files.\n\nFollow this description to increase the limit:\n[https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit](https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit)\n\n\n## Alternatives\n\n* [chokidar](https://github.com/paulmillr/chokidar)\n* [gaze](https://github.com/shama/gaze)\n* [mikeal/watch](https://github.com/mikeal/watch)\n\n## Contributors\n\nThanks goes to [all wonderful people](https://github.com/yuanchuan/node-watch/graphs/contributors) who have helped this project.\n\n## License\nMIT\n\nCopyright (c) 2012-2021 [yuanchuan](https://github.com/yuanchuan)\n","publish_time":1588330540855,"_cnpm_publish_time":1588330540855,"dist-tags":{"latest":"0.7.4"}}