chokidar
Chokidar is a fast, efficient file watching library for Node.js that provides a reliable cross-platform API for monitoring file system changes. Node.js's built-…
Installation
npm install chokidar
yarn add chokidar
pnpm add chokidar
Import
import chokidar from 'chokidar';
Quick Example
import chokidar from 'chokidar';
const watcher = chokidar.watch('src/**/*.ts', {
ignored: /node_modules/,
persistent: true,
});
watcher
.on('add', (path) => console.log(`Added: ${path}`))
.on('change', (path) => console.log(`Changed: ${path}`))
.on('unlink', (path) => console.log(`Removed: ${path}`));About chokidar
Chokidar is a fast, efficient file watching library for Node.js that provides a reliable cross-platform API for monitoring file system changes. Node.js's built-in fs.watch has well-known issues including inconsistent behavior across operating systems, not reporting filenames on macOS, emitting duplicate events, not supporting recursive watching on all platforms, and missing events entirely in some scenarios. Chokidar solves these problems by using a combination of native file watching (FSEvents on macOS, inotify on Linux, ReadDirectoryChanges on Windows) with intelligent fallbacks and polling. The library detects file additions, modifications, deletions, directory additions and removals, and provides a clean event-based API: watcher.on('add', path => ...).on('change', path => ...).on('unlink', path => ...). Chokidar supports glob patterns for watched paths, ignored patterns for excluding files, atomic writes detection, and configurable polling intervals for network filesystems. The library is the file watching engine used by webpack, Vite, Rollup, nodemon, Parcel, Karma, and many other development tools. Chokidar handles the complexity of cross-platform file watching so that tools can focus on responding to changes rather than detecting them.
Quick Facts
| Package | chokidar |
| Category | File System |
| Weekly Downloads | 30M+ |
| License | MIT |
| Install | npm install chokidar |
Related Packages
Nodemon is a utility that monitors for file changes in your Node.js application and automatically re…
glob is a library for matching files using glob patterns — the wildcard syntax familiar from shell c…
fast-glob is a high-performance glob matching library for Node.js that provides significant speed im…
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.