Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

chokidar 3.6.0

Minimal and efficient cross-platform file watching library
Package summary
Share
0
issues
0
licenses
Package created
26 Apr 2012
Version published
6 Feb 2024
Maintainers
2
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does chokidar do?

Chokidar is a highly efficient and minimalistic cross-platform library in Node.js that is designed for file watching. It addresses the common issues associated with Node.js's fs.watch and fs.watchFile, which include not reporting filenames on MacOS, not reporting events when using certain editors on MacOS, often reporting events twice, and not supporting recursive watching among others. By using fs.watch and fs.watchFile for watching and normalizing the events it receives, Chokidar provides a robust solution to these problems. Chokidar is the library of choice for successful implementation in production environments for major software like Microsoft's Visual Studio Code, Gulp, and Webpack.

How do you use chokidar?

To use Chokidar, you need to install it via npm using the command npm install chokidar. Once installed, you can import it into your project using require and start watching files or directories as shown in the following example:

const chokidar = require('chokidar');

// One-liner for the current directory, logs all events
chokidar.watch('.').on('all', (event, path) => {
  console.log(event, path);
});

// More complex example with event listeners
const watcher = chokidar.watch('file, dir, glob, or array', {
  ignored: /(^|[\/\\])\../, // ignore dotfiles
  persistent: true
});

const log = console.log.bind(console);

// Add event listeners
watcher
  .on('add', path => log(`File ${path} has been added`))
  .on('change', path => log(`File ${path} has been changed`))
  .// ...

You can add new files to the watcher, get the list of actual paths being watched, stop watching certain files, and even stop watching completely using watcher.add(), watcher.getWatched(), watcher.unwatch(), and watcher.close() respectively.

Where are the chokidar docs?

The complete documentation and API reference for Chokidar can be found directly in its repository on GitHub at https://github.com/paulmillr/chokidar. It provides a complete guide on how to use Chokidar's methods and options, handle events, use the CLI, as well as troubleshooting tips and more details about its inner workings.