{"_id":"chokidar@6.0.0","bugs":{"url":"https://github.com/paulmillr/chokidar/issues"},"dist":{"shasum":"66bb84678ab40b8d25679d71f3955bd206ab618b","tarball":"http://registry-npm.ywwl.com/chokidar/download/chokidar-6.0.0.tgz","integrity":"sha512-Ec2Z7wpcKBiMpR7DxteoqS/sq5G5d2A4fpxzPv6+fD7xNNdrTghn7L11YwV5EN1B3i72Erc3XVT5FkWIDx90+A==","fileCount":15,"unpackedSize":201589,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/chokidar@6.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCHmZ743F9QDT38M9i4hpjrKthWcD4r4Lf2PpjkM1dGhwIhALBhAn8YOOBOJ6wDynkC/aEYApP2o/li2djitErD9XuC"}],"size":47212,"noattachment":false,"key":"/chokidar/-/chokidar-6.0.0.tgz"},"main":"./index.js","name":"chokidar","type":"module","types":"./index.d.ts","author":{"url":"https://paulmillr.com","name":"Paul Miller"},"engines":{"node":">= 22.22"},"exports":{".":{"default":"./index.js"}},"funding":"https://paulmillr.com/funding/","gitHead":"4130839be8ca2dd05692837cde3145276f58f8bf","license":"MIT","scripts":{"test":"node index.test.js","build":"tsc","format":"prettier --write src benchmark scripts .github/funding.yml .github/workflows package.json README.md","test:vms":"node scripts/test-vms.mjs","benchmark":"node benchmark/bench.mjs","test:bun1":"bun index.test.js"},"version":"6.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"c83e2b4f-172f-414b-8bde-fde3b67f58fb"},"approver":{"name":"paulmillr","email":"paul@paulmillr.com"}},"homepage":"https://github.com/paulmillr/chokidar","keywords":["fs","watch","watchFile","watcher","watching","file","fsevents"],"repository":{"url":"git+https://github.com/paulmillr/chokidar.git","type":"git"},"_npmVersion":"12.0.2","description":"Minimal and efficient cross-platform file watching library","directories":{},"maintainers":[{"name":"paulmillr","email":"paul@paulmillr.com"}],"sideEffects":false,"_nodeVersion":"24.19.0","dependencies":{"readdirp":"^5.1.1"},"devDependencies":{"prettier":"3.8.3","typescript":"6.0.3","@types/node":"26.5.0","@paulmillr/jsbt":"0.7.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/chokidar_6.0.0_1792443161438_0.7554096830635735"},"_hasShrinkwrap":false,"readme":"# Chokidar [![Weekly downloads](https://img.shields.io/npm/dw/chokidar.svg)](https://github.com/paulmillr/chokidar)\n\nMinimal and efficient cross-platform file watching library\n\n## Why?\n\nRaw `fs.watch` / `fs.watchFile` are useless: `fs.watch` reports many changes as an\nnon-transparent `rename`, can fire twice for one change, and recursive watching differs across\nplatforms. Chokidar normalizes all of that:\n\n- Proper `add` / `change` / `unlink` (and `addDir` / `unlinkDir`) events, verified, deduplicated, with\n  paths on every platform.\n- Native `fs.watch` by default, which keeps CPU usage down; stat-based polling is available for\n  network and other unusual filesystems.\n- Recursive watching everywhere, with an optional depth limit, path filtering, and symlink support.\n- Editor \"atomic writes\" (`atomic`) and chunked writes of large files (`awaitWriteFinish`) are\n  handled.\n\nChokidar watches everything under the paths you give it, so scope them (and use `ignored` /\n`depth`) rather than watching more than you need.\n\nMade for [Brunch](https://brunch.io/) in 2012, it is now used in\n[30+ million projects](https://www.npmjs.com/browse/depended/chokidar) and has proven itself\nin production environments. The current major is [v6 (Oct 2026)](#changelog) - with lots of major improvements.\n\n## Getting started\n\n```sh\nnpm install chokidar\n```\n\n```js\nimport chokidar from 'chokidar';\n// or: import { watch } from 'chokidar';\n// or: const chokidar = require('chokidar');\n\nchokidar.watch('src').on('all', (event, path) => console.log(event, path));\n```\n\nA fuller example:\n\n```js\nimport chokidar from 'chokidar';\n\nconst watcher = chokidar.watch('src', {\n  // strings are exact paths (not globs), regexes test the whole path, functions get (path, stats?)\n  ignored: [\n    /(^|\\/)\\../, // dotfiles\n    (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only .js files\n  ],\n  ignoreInitial: true, // don't emit add/addDir for files that already exist\n});\n\nwatcher\n  .on('add', (path, stats) => console.log('added', path, stats?.size))\n  .on('change', (path) => console.log('changed', path))\n  .on('unlink', (path) => console.log('removed', path))\n  .on('ready', () => console.log('initial scan done'))\n  .on('error', (err) => console.error(err));\n\nwatcher.add(['lib', 'index.js']); // add more paths later\nwatcher.unwatch('lib'); // synchronous\nconsole.log(watcher.getWatched()); // { '/abs': ['src'], '/abs/src': ['a.js', 'sub'], ... }\nawait watcher.close(); // async and terminal: create a new watcher to resume\n```\n\nRecipes:\n\n```js\n// Large or chunked writes, and editors that save via temp file + rename\nchokidar.watch('uploads', {\n  awaitWriteFinish: { stabilityThreshold: 2000, pollInterval: 100 }, // wait for size to settle\n  atomic: 100, // unlink + add within 100 ms becomes one change\n});\n\n// Network or otherwise unusual filesystems where fs.watch is unreliable\nchokidar.watch('/mnt/nfs/data', { backend: 'polling', pollingInterval: 500 });\n```\n\n## API\n\n`chokidar.watch(paths, [options])` returns an [`FSWatcher`](#methods). `paths` is a string or an\narray of strings; files are watched, directories are watched recursively. All options with their\ndefaults:\n\n```js\nchokidar.watch('dir-or-file', {\n  // Filtering\n  ignored: undefined, // matcher or array of matchers, see below\n  ignoreInitial: false,\n  followSymlinks: true,\n  cwd: undefined,\n  depth: undefined, // unlimited\n  // Backend\n  backend: 'auto', // 'auto' | 'native' | 'native-recursive' | 'polling'\n  pollingInterval: 100, // polling backend only\n  pollingBinaryInterval: 300, // polling backend only\n  // Event timing\n  atomic: true, // false with backend: 'polling'; or a number of ms\n  awaitWriteFinish: false, // or true, or { stabilityThreshold: 2000, pollInterval: 100 }\n  alwaysStat: false,\n  // Errors and lifecycle\n  ignorePermissionErrors: false,\n  persistent: true,\n});\n```\n\n#### Filtering\n\n- `ignored` (default: none). One matcher or an array of matchers. The whole path is tested (as\n  passed to `watch()`, joined with `cwd` if set), not just the basename. Ignoring a directory\n  ignores everything inside it. Directories above a path passed to `watch()` / `add()` are never\n  ignored, so a missing path is still watched through its parent; their other contents are still\n  filtered. A matcher is one of:\n  - a **string**: an exact path. Relative strings are resolved against `cwd` (or the process\n    cwd). Globs are not supported; see [upgrading](#upgrading) for the replacement pattern.\n  - a **RegExp**: tested against the whole path with forward slashes, on Windows too, e.g.\n    `/(^|\\/)\\../` for dotfiles or `/\\/node_modules\\//`.\n  - a **function** `(path, stats?) => boolean`: may be called twice per path, first with the path\n    only, then with the path and its [`fs.Stats`](https://nodejs.org/api/fs.html#class-fsstats), so\n    guard stat-based checks with `stats?.isFile()`.\n  - an **object** `{ path, recursive?: boolean }`: an exact path, plus its subtree when\n    `recursive` is true.\n- `ignoreInitial` (default: `false`). When `true`, `add` / `addDir` are not emitted for paths\n  discovered during the initial scan (before `ready`).\n- `followSymlinks` (default: `true`). When `false`, symlinks are watched as themselves rather\n  than followed; retargeting a link emits `change`.\n- `cwd` (no default). Base directory that `paths` are resolved against; emitted paths are\n  relative to it.\n- `depth` (default: `undefined`, unlimited). Maximum number of subdirectory levels to traverse.\n  `Infinity` means unlimited.\n\n#### Backend\n\n- `backend` (default: `auto`). Selects the filesystem observation backend:\n  - `auto` uses native recursive watching on macOS and Windows and native per-directory\n    watching elsewhere.\n  - `native` uses one `fs.watch` subscription per directory.\n  - `native-recursive` prefers `fs.watch({ recursive: true })` and falls back to per-directory\n    watching where recursive watching is unavailable. A finite `depth` also uses per-directory\n    watching so nothing beyond the requested tree is subscribed.\n  - `polling` uses Chokidar's stat-based polling scheduler. Useful for network and other\n    non-standard filesystems; uses more CPU.\n- `pollingInterval` (default: `100`) and `pollingBinaryInterval` (default: `300`, for recognized\n  binary file extensions): polling periods in milliseconds, polling backend only. Polling compares\n  size, modification time, existence, and (except on Windows) inode between polls; an in-place\n  write that changes none of these is not detected.\n- Environment overrides: `CHOKIDAR_USEPOLLING` forces polling when truthy and disables it when\n  falsy, even if `backend: 'polling'` is set in code; `CHOKIDAR_INTERVAL` overrides\n  `pollingInterval`.\n- Deprecated aliases kept for compatibility: `usePolling: true` means `backend: 'polling'`;\n  `interval` / `binaryInterval` mean `pollingInterval` / `pollingBinaryInterval` (the new\n  spellings win when both are given).\n\n#### Event timing\n\n- `atomic` (default: `true` with native backends, `false` with polling; or a number of\n  milliseconds). Editors that save through a temp file and rename produce `unlink` then `add`;\n  within the window (100 ms by default) Chokidar emits a single `change` instead. It also ignores\n  common editor temp files (`.swp` / `.swx`, `~` backups, Sublime `.subl*.tmp`).\n- `awaitWriteFinish` (default: `false`). By default `add` / `change` fire as soon as a file\n  appears or changes, which for large or chunked writes can be before the write is finished.\n  Set to `true` (or `{ stabilityThreshold: 2000, pollInterval: 100 }`) to hold `add` / `change`\n  until the file size has stayed constant for `stabilityThreshold` ms, checked every\n  `pollInterval` ms. The right threshold depends on the OS and hardware: higher is safer and less\n  responsive. Events from the initial scan are not held.\n- `alwaysStat` (default: `false`). Always pass an\n  [`fs.Stats`](https://nodejs.org/api/fs.html#class-fsstats) object with `add` / `addDir` /\n  `change`, issuing an extra `stat` when the backend did not provide one.\n\n#### Errors and lifecycle\n\n- `ignorePermissionErrors` (default: `false`). When `true`, `EPERM` / `EACCES` errors from\n  unreadable paths are suppressed instead of emitted.\n- `persistent` (default: `true`). Whether the watcher keeps the process alive while it is\n  watching.\n\n### Methods\n\n- `.add(paths)`: start watching more files or directories (string or array).\n- `.unwatch(paths)`: stop watching files or directories (string or array). Synchronous; the paths\n  stay ignored until they are `.add()`ed again.\n- `.close()`: **async and terminal.** Removes all listeners and stops all owned work. Repeated\n  calls return the same Promise; once closing has started, `.add()` throws and a new `FSWatcher`\n  is required.\n- `.getWatched()`: an object whose keys are the watched directories (absolute unless `cwd` is\n  set) and whose values are arrays of the entry names inside each.\n- `.on(event, listener)`: `FSWatcher` is an `EventEmitter`; see events below.\n\n### Events\n\n| Event                     | Listener arguments                                                 |\n| ------------------------- | ------------------------------------------------------------------ |\n| `add`, `addDir`, `change` | `(path, stats?)`; `stats` when available, always with `alwaysStat` |\n| `unlink`, `unlinkDir`     | `(path)`                                                           |\n| `all`                     | `(event, path, stats?)` for each of the five events above          |\n| `ready`                   | none; the initial scan is complete                                 |\n| `error`                   | `(error)`                                                          |\n| `raw`                     | `(event, path, details)` from the backend; unstable, use with care |\n\n## Troubleshooting\n\n- **`ENOSPC: System limit for number of file watchers reached`** (Linux): the inotify watch limit\n  is exhausted. Raise it with\n  `echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`, or\n  watch less: narrow `paths`, add `ignored` (for example `node_modules`), set `depth`.\n- **`EMFILE: too many open files`**: the process file-descriptor limit is exhausted. Watch less as\n  above, raise the limit (`ulimit -n 65536`), or use `backend: 'polling'`, which holds no watch\n  handles at the cost of CPU.\n- `fsevents`-related install errors (`WARN optional dep failed`, `fsevents is not a constructor`)\n  are solved by upgrading to v4+.\n\n## Changelog\n\n- **v6 (Oct 2026):** complete rewrite; new fs.watch(recursive) backend on macos + windows; requires Node.js 22+\n- **v5 (Nov 2025):** ESM-only; requires Node.js 20+\n- **v4 (Sep 2024):** remove glob support & fsevents dependency, decrease dep count from 13\n  to 1; requires Node.js 14+\n- **v3 (Apr 2019):** massive CPU & RAM consumption improvements; 17x decrease in pkg size + deps; requires Node.js 8.16+\n- **v2 (Dec 2017):** posix-style globs; bugfixes\n- **v1 (Apr 2015):** glob support, symlink support, tons of bugfixes; requires Node.js 0.8+\n- **v0.1 (Apr 2012):** extracted from\n  [Brunch](https://github.com/brunch/brunch/blob/9847a065aea300da99bd0753f90354cde9de1261/src/helpers.coffee#L66)\n\n### Upgrading\n\nVersion 6 requires Node.js 22.22 or newer. An `FSWatcher` cannot be reopened after `.close()`\nstarts; construct a new watcher instead. Polling now defaults `atomic` to `false`, while an\nexplicit `atomic` value is preserved. Use `pollingInterval` and `pollingBinaryInterval` for\npolling configuration; the v5 `interval` and `binaryInterval` spellings remain as deprecated\naliases.\n\nGlobs were removed in v4. To replicate them:\n\n```js\n// v3\nchokidar.watch('**/*.js');\nchokidar.watch('./directory/**/*');\n\n// v4+: filter instead\nchokidar.watch('.', {\n  ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files\n});\nchokidar.watch('./directory');\n\n// or expand the glob yourself\nimport { glob } from 'node:fs/promises';\nconst watcher = chokidar.watch(await Array.fromAsync(glob('**/*.js')));\n\n// unwatching\nwatcher.unwatch('**/*.js'); // v3\nwatcher.unwatch(await Array.fromAsync(glob('**/*.js'))); // v4+\n```\n\n## Contributing\n\nRun `npm ci && npm run build && npm test` (tests import the built files, so build first).\nInternals and design requirements are documented in [docs/architecture.md](docs/architecture.md);\nthe cross-platform CI setup is in [docs/vm-testing.md](docs/vm-testing.md).\n\n## Also\n\nWhy was chokidar named this way? What's the meaning behind it?\n\n> Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.\n\n## License\n\nMIT (c) Paul Miller (<https://paulmillr.com>), see [LICENSE](LICENSE) file.\n","publish_time":1792443161519,"_cnpm_publish_time":1792443161519,"dist-tags":{"latest":"6.0.0"}}