Chokidar CLI

3.0.0 · maintenance · verified Sun Apr 19

Chokidar CLI is an ultra-fast, cross-platform command-line utility designed to watch file system changes and execute arbitrary commands or stream event output. It is built upon the robust and widely adopted `chokidar` library, which is known for its battle-tested stability and efficient file watching across various operating systems, handling quirks of `fs.watch` and `fs.watchFile` by normalizing events and supporting atomic/chunked writes. Currently at version 3.0.0, this tool provides a simple interface for developers to integrate automated tasks, such as compilation or testing, directly into their workflow upon file modifications. While the underlying `chokidar` library has seen recent updates (v4 and v5 as of late 2024/2025), `chokidar-cli` itself has not had a major release since v3.0.0 in July 2021, suggesting a slower release cadence for the CLI wrapper. Its key differentiators lie in abstracting the complexities of file system event handling and providing a straightforward command-line interface for common automation needs without requiring programmatic setup.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global installation, watching a glob pattern for `.js` files, and executing a command with event and path details on changes.

#!/bin/bash

# Install chokidar-cli globally for easy command access
npm install -g chokidar-cli

# Create a dummy project directory and a file
mkdir -p my-watched-project/src
echo "// Initial content" > my-watched-project/src/app.js

# Navigate into the project directory
cd my-watched-project

echo "Watching for changes in src/**/*.js. Try modifying src/app.js..."

# Run chokidar to watch JavaScript files and execute a simple echo command
# The -c flag runs a command, and {event} and {path} are placeholders
chokidar "src/**/*.js" -c "echo 'File {path} was {event}ed!' && ls -la src"

# To stop watching, press Ctrl+C in the terminal where chokidar is running.

# Example of how to trigger an event (run this in a separate terminal after starting chokidar):
# echo "console.log('updated content');" >> src/app.js
# rm src/app.js
# echo "// New file" > src/another.js

view raw JSON →