{"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.2","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":"2138d6b2cc35f0f5810f99de715e655201a4b192","_id":"node-watch@0.6.2","_npmVersion":"6.5.0","_nodeVersion":"11.7.0","_npmUser":{"name":"yuanchuan","email":"yuanchuan23@gmail.com"},"dist":{"integrity":"sha512-qmb/2ehVk1DC4gZYox7JgWXNucKnVk7uQmcoSeRaC7kzXsT8VOPIe7mbrR9Vc2TpGggS2yGUcgC98A2fKE53AA==","shasum":"48fd517b527ec21ac4f5f981aad2a6ddebc0131c","tarball":"http://registry-npm.ywwl.com/node-watch/download/node-watch-0.6.2.tgz","fileCount":13,"unpackedSize":50814,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJct+0UCRA9TVsSAnZWagAAJCgQAIbhXBdm1y+K1GhKXRa+\ndY6FW9mILzXpgKt4k30edSAz+bHc69CuPue2o5bS5NIOjpneTzKJGIlWfpQW\nzDEhZlPfZdd19Pl1TExC7ijlLEvBanozZMgSVf9iA+fLwigo5P5/e+CzdPY+\nwp6R9gyMctb0hOMkePqDBdeQVDR9Cz95tfq42bjFxZw8DYQDbWLRFuTnt7Ej\nqmDJS90NyzigAJbChtg8Q4DmEKkETRf8gysRRMJ9rKKsPgX9GP8Pr0YtjdQ9\n0WFIfWApWvTeFIfDfuKAMv4J5ddZxd1NZpa0ExF2TJxFLrfVLjp/Ie30L0l+\nYxMKU8FBN4J6SBGxcQgDYCcc5K8VX9/80oQ/W5J+fCPQC9OHEiuWUZDbVQlP\nR58i/jlqm1LiUFIc+L+IBxgG/SiR9ETTqb46jawblL4CGrwEhVk/gD4pFyxB\nTet1xnn4CQjbl5nPKyIPPa3UpGtaMHWBppJguU9lDhq7t/2xcRd+ORYoS7cJ\naX4zPCPXFa6R1xcIj9xDsIevyZb9xp63Ho/VLyDwn+rMRffT++/OpE1dpxx+\nxRLbO1kK1SvB77/hiOKQ1zDW0m0N7NIcgpXet9blqzxh9JeNZEV6gAKjHzFx\nRjOJihFpa0vybZTnyC5ZV4aLnqxheOfUqq4feFlZs3GHQt3yFNlyYpvV9cWd\nNddH\r\n=0g4N\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDsekFNg47v5ky2+evIpQhOsgRzgul0NA5lSAbX8wo52AiEA8b6NfmkFZWaenKkmI+pHDL2YW85p3UKCQj3PEn87ylY="}],"size":12897,"noattachment":false,"key":"/node-watch/-/node-watch-0.6.2.tgz"},"maintainers":[{"name":"yuanchuan","email":"yuanchuan23@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/node-watch_0.6.2_1555557652012_0.3560177814417165"},"_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":1555557652130,"_cnpm_publish_time":1555557652130,"dist-tags":{"latest":"0.7.4"}}