[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10131":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":34,"discoverSource":35},10131,"chokidar","paulmillr\u002Fchokidar","paulmillr","Minimal and efficient cross-platform file watching library","https:\u002F\u002Fpaulmillr.com",null,"TypeScript",12135,626,85,32,0,2,7,33,8,43.39,"MIT License",false,"main",[5,26,27,28,29,30],"filesystem","fsevents","nodejs","watch-files","watcher","2026-06-12 02:02:17","# Chokidar [![Weekly downloads](https:\u002F\u002Fimg.shields.io\u002Fnpm\u002Fdw\u002Fchokidar.svg)](https:\u002F\u002Fgithub.com\u002Fpaulmillr\u002Fchokidar)\n\nMinimal and efficient cross-platform file watching library\n\n## Why?\n\nThere are many reasons to prefer Chokidar to raw fs.watch \u002F fs.watchFile in 2026:\n\n- Events are properly reported\n  - macOS events report filenames\n  - events are not reported twice\n  - changes are reported as add \u002F change \u002F unlink instead of useless `rename`\n- Atomic writes are supported, using `atomic` option\n  - Some file editors use them\n- Chunked writes are supported, using `awaitWriteFinish` option\n  - Large files are commonly written in chunks\n- File \u002F dir filtering is supported\n- Symbolic links are supported\n- Recursive watching is always supported, instead of partial when using raw events\n  - Includes a way to limit recursion depth\n\nChokidar relies on the Node.js core `fs` module, but when using\n`fs.watch` and `fs.watchFile` for watching, it normalizes the events it\nreceives, often checking for truth by getting file stats and\u002For dir contents.\nThe `fs.watch`-based implementation is the default, which\navoids polling and keeps CPU usage down. Be advised that chokidar will initiate\nwatchers recursively for everything within scope of the paths that have been\nspecified, so be judicious about not wasting system resources by watching much\nmore than needed. For some cases, `fs.watchFile`, which utilizes polling and uses more resources, is used.\n\nMade for [Brunch](https:\u002F\u002Fbrunch.io\u002F) in 2012,\nit is now used in [~30 million repositories](https:\u002F\u002Fwww.npmjs.com\u002Fbrowse\u002Fdepended\u002Fchokidar) and\nhas proven itself in production environments.\n\n- **Nov 2025 update:** v5 is out. Makes package ESM-only and increases minimum node.js requirement to v20.\n- **Sep 2024 update:** v4 is out! It decreases dependency count from 13 to 1, removes\nsupport for globs, adds support for ESM \u002F Common.js modules, and bumps minimum node.js version from v8 to v14.\nCheck out [upgrading](#upgrading).\n\n## Getting started\n\nInstall with npm:\n\n```sh\nnpm install chokidar\n```\n\nUse it in your code:\n\n```javascript\nimport chokidar from 'chokidar';\n\n\u002F\u002F One-liner for current directory\nchokidar.watch('.').on('all', (event, path) => {\n  console.log(event, path);\n});\n\n\u002F\u002F Extended options\n\u002F\u002F ----------------\n\n\u002F\u002F Initialize watcher.\nconst watcher = chokidar.watch('file, dir, or array', {\n  ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), \u002F\u002F only watch js files\n  persistent: true,\n});\n\n\u002F\u002F Something to use when events are received.\nconst log = console.log.bind(console);\n\u002F\u002F Add event listeners.\nwatcher\n  .on('add', (path) => log(`File ${path} has been added`))\n  .on('change', (path) => log(`File ${path} has been changed`))\n  .on('unlink', (path) => log(`File ${path} has been removed`));\n\n\u002F\u002F More possible events.\nwatcher\n  .on('addDir', (path) => log(`Directory ${path} has been added`))\n  .on('unlinkDir', (path) => log(`Directory ${path} has been removed`))\n  .on('error', (error) => log(`Watcher error: ${error}`))\n  .on('ready', () => log('Initial scan complete. Ready for changes'))\n  .on('raw', (event, path, details) => {\n    \u002F\u002F internal\n    log('Raw event info:', event, path, details);\n  });\n\n\u002F\u002F 'add', 'addDir' and 'change' events also receive stat() results as second\n\u002F\u002F argument when available: https:\u002F\u002Fnodejs.org\u002Fapi\u002Ffs.html#fs_class_fs_stats\nwatcher.on('change', (path, stats) => {\n  if (stats) console.log(`File ${path} changed size to ${stats.size}`);\n});\n\n\u002F\u002F Watch new files.\nwatcher.add('new-file');\nwatcher.add(['new-file-2', 'new-file-3']);\n\n\u002F\u002F Get list of actual paths being watched on the filesystem\nlet watchedPaths = watcher.getWatched();\n\n\u002F\u002F Un-watch some files.\nawait watcher.unwatch('new-file');\n\n\u002F\u002F Stop watching. The method is async!\nawait watcher.close().then(() => console.log('closed'));\n\n\u002F\u002F Full list of options. See below for descriptions.\n\u002F\u002F Do not use this example!\nchokidar.watch('file', {\n  persistent: true,\n\n  \u002F\u002F ignore .txt files\n  ignored: (file) => file.endsWith('.txt'),\n  \u002F\u002F watch only .txt files\n  \u002F\u002F ignored: (file, _stats) => _stats?.isFile() && !file.endsWith('.txt'),\n\n  awaitWriteFinish: true, \u002F\u002F emit single event when chunked writes are completed\n  atomic: true, \u002F\u002F emit proper events when \"atomic writes\" (mv _tmp file) are used\n\n  \u002F\u002F The options also allow specifying custom intervals in ms\n  \u002F\u002F awaitWriteFinish: {\n  \u002F\u002F   stabilityThreshold: 2000,\n  \u002F\u002F   pollInterval: 100\n  \u002F\u002F },\n  \u002F\u002F atomic: 100,\n\n  interval: 100,\n  binaryInterval: 300,\n\n  cwd: '.',\n  depth: 99,\n\n  followSymlinks: true,\n  ignoreInitial: false,\n  ignorePermissionErrors: false,\n  usePolling: false,\n  alwaysStat: false,\n});\n```\n\n`chokidar.watch(paths, [options])`\n\n- `paths` (string or array of strings). Paths to files, dirs to be watched\n  recursively.\n- `options` (object) Options object as defined below:\n\n#### Persistence\n\n- `persistent` (default: `true`). Indicates whether the process\n  should continue to run as long as files are being watched.\n\n#### Path filtering\n\n- `ignored` function, regex, or path. Defines files\u002Fpaths to be ignored.\n  The whole relative or absolute path is tested, not just filename. If a function with two arguments\n  is provided, it gets called twice per path - once with a single argument (the path), second\n  time with two arguments (the path and the\n  [`fs.Stats`](https:\u002F\u002Fnodejs.org\u002Fapi\u002Ffs.html#fs_class_fs_stats)\n  object of that path).\n- `ignoreInitial` (default: `false`). If set to `false` then `add`\u002F`addDir` events are also emitted for matching paths while\n  instantiating the watching as chokidar discovers these file paths (before the `ready` event).\n- `followSymlinks` (default: `true`). When `false`, only the\n  symlinks themselves will be watched for changes instead of following\n  the link references and bubbling events through the link's path.\n- `cwd` (no default). The base directory from which watch `paths` are to be\n  derived. Paths emitted with events will be relative to this.\n\n#### Performance\n\n- `usePolling` (default: `false`).\n  Whether to use fs.watchFile (backed by polling), or fs.watch. If polling\n  leads to high CPU utilization, consider setting this to `false`. It is\n  typically necessary to **set this to `true` to successfully watch files over\n  a network**, and it may be necessary to successfully watch files in other\n  non-standard situations. Setting to `true` explicitly on MacOS overrides the\n  `useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable\n  to true (1) or false (0) in order to override this option.\n- _Polling-specific settings_ (effective when `usePolling: true`)\n  - `interval` (default: `100`). Interval of file system polling, in milliseconds. You may also\n    set the CHOKIDAR_INTERVAL env variable to override this option.\n  - `binaryInterval` (default: `300`). Interval of file system\n    polling for binary files.\n    ([see list of binary extensions](https:\u002F\u002Fgithub.com\u002Fsindresorhus\u002Fbinary-extensions\u002Fblob\u002Fmaster\u002Fbinary-extensions.json))\n- `alwaysStat` (default: `false`). If relying upon the\n  [`fs.Stats`](https:\u002F\u002Fnodejs.org\u002Fapi\u002Ffs.html#fs_class_fs_stats)\n  object that may get passed with `add`, `addDir`, and `change` events, set\n  this to `true` to ensure it is provided even in cases where it wasn't\n  already available from the underlying watch events.\n- `depth` (default: `undefined`). If set, limits how many levels of\n  subdirectories will be traversed.\n- `awaitWriteFinish` (default: `false`).\n  By default, the `add` event will fire when a file first appears on disk, before\n  the entire file has been written. Furthermore, in some cases some `change`\n  events will be emitted while the file is being written. In some cases,\n  especially when watching for large files there will be a need to wait for the\n  write operation to finish before responding to a file creation or modification.\n  Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,\n  holding its `add` and `change` events until the size does not change for a\n  configurable amount of time. The appropriate duration setting is heavily\n  dependent on the OS and hardware. For accurate detection this parameter should\n  be relatively high, making file watching much less responsive.\n  Use with caution.\n  - _`options.awaitWriteFinish` can be set to an object in order to adjust\n    timing params:_\n  - `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in\n    milliseconds for a file size to remain constant before emitting its event.\n  - `awaitWriteFinish.pollInterval` (default: 100). File size polling interval, in milliseconds.\n\n#### Errors\n\n- `ignorePermissionErrors` (default: `false`). Indicates whether to watch files\n  that don't have read permissions if possible. If watching fails due to `EPERM`\n  or `EACCES` with this set to `true`, the errors will be suppressed silently.\n- `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).\n  Automatically filters out artifacts that occur when using editors that use\n  \"atomic writes\" instead of writing directly to the source file. If a file is\n  re-added within 100 ms of being deleted, Chokidar emits a `change` event\n  rather than `unlink` then `add`. If the default of 100 ms does not work well\n  for you, you can override it by setting `atomic` to a custom value, in\n  milliseconds.\n\n### Methods & Events\n\n`chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:\n\n- `.add(path \u002F paths)`: Add files, directories for tracking.\n  Takes an array of strings or just one string.\n- `.on(event, callback)`: Listen for an FS event.\n  Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,\n  `raw`, `error`.\n  Additionally `all` is available which gets emitted with the underlying event\n  name and path for every event other than `ready`, `raw`, and `error`. `raw` is internal, use it carefully.\n- `.unwatch(path \u002F paths)`: Stop watching files or directories.\n  Takes an array of strings or just one string.\n- `.close()`: **async** Removes all listeners from watched files. Asynchronous, returns Promise. Use with `await` to ensure bugs don't happen.\n- `.getWatched()`: Returns an object representing all the paths on the file\n  system being watched by this `FSWatcher` instance. The object's keys are all the\n  directories (using absolute paths unless the `cwd` option was used), and the\n  values are arrays of the names of the items contained in each directory.\n\n### CLI\n\nCheck out third party [chokidar-cli](https:\u002F\u002Fgithub.com\u002Fopen-cli-tools\u002Fchokidar-cli),\nwhich allows to execute a command on each change, or get a stdio stream of change events.\n\n## Troubleshooting\n\nSometimes, Chokidar runs out of file handles, causing `EMFILE` and `ENOSP` errors:\n\n- `bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell`\n- `Error: watch \u002Fhome\u002F ENOSPC`\n\nThere are two things that can cause it.\n\n1. Exhausted file handles for generic fs operations\n   - Can be solved by using [graceful-fs](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fgraceful-fs),\n     which can monkey-patch native `fs` module used by chokidar: `let fs = require('fs'); let grfs = require('graceful-fs'); grfs.gracefulify(fs);`\n   - Can also be solved by tuning OS: `echo fs.inotify.max_user_watches=524288 | sudo tee -a \u002Fetc\u002Fsysctl.conf && sudo sysctl -p`.\n2. Exhausted file handles for `fs.watch`\n   - Can't seem to be solved by graceful-fs or OS tuning\n   - It's possible to start using `usePolling: true`, which will switch backend to resource-intensive `fs.watchFile`\n\nAll fsevents-related issues (`WARN optional dep failed`, `fsevents is not a constructor`) are solved by upgrading to v4+.\n\n## Changelog\n\n- **v4 (Sep 2024):** remove glob support and bundled fsevents. Decrease dependency count from 13 to 1. Rewrite in typescript. Bumps minimum node.js requirement to v14+\n- **v3 (Apr 2019):** massive CPU & RAM consumption improvements; reduces deps \u002F package size by a factor of 17x and bumps Node.js requirement to v8.16+.\n- **v2 (Dec 2017):** globs are now posix-style-only. Tons of bugfixes.\n- **v1 (Apr 2015):** glob support, symlink support, tons of bugfixes. Node 0.8+ is supported\n- **v0.1 (Apr 2012):** Initial release, extracted from [Brunch](https:\u002F\u002Fgithub.com\u002Fbrunch\u002Fbrunch\u002Fblob\u002F9847a065aea300da99bd0753f90354cde9de1261\u002Fsrc\u002Fhelpers.coffee#L66)\n\n### Upgrading\n\nIf you've used globs before and want do replicate the functionality with v4:\n\n```js\n\u002F\u002F v3\nchok.watch('**\u002F*.js');\nchok.watch('.\u002Fdirectory\u002F**\u002F*');\n\n\u002F\u002F v4\nchok.watch('.', {\n  ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), \u002F\u002F only watch js files\n});\nchok.watch('.\u002Fdirectory');\n\n\u002F\u002F other way\nimport { glob } from 'node:fs\u002Fpromises';\nconst watcher = watch(await Array.fromAsync(glob('**\u002F*.js')));\n\n\u002F\u002F unwatching\n\u002F\u002F v3\nchok.unwatch('**\u002F*.js');\n\u002F\u002F v4\nchok.unwatch(await Array.fromAsync(glob('**\u002F*.js')));\n```\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 (\u003Chttps:\u002F\u002Fpaulmillr.com>), see [LICENSE](LICENSE) file.\n","Chokidar 是一个轻量级且高效的跨平台文件监控库。它支持原子写入和分块写入，确保事件准确报告，包括文件的添加、修改和删除，并且能够递归监控目录及其子目录中的文件变化，同时提供了对符号链接的支持以及灵活的文件\u002F目录过滤功能。基于 Node.js 核心 fs 模块构建，Chokidar 通过优化事件处理逻辑，在保持低CPU占用的同时提供比原生 fs.watch 和 fs.watchFile 更稳定可靠的文件监控能力。适用于需要实时响应文件系统变动的各种开发场景，如自动化构建工具、热重载服务等。","2026-06-11 03:26:46","top_topic"]