Performance: Watching files for changes
MEDIUM IMPACT
Watching files for changes impacts CPU usage and memory consumption during development, affecting responsiveness and system load.
const chokidar = require('chokidar'); const watcher = chokidar.watch('.', { ignored: /node_modules/, persistent: true }); watcher.on('change', path => { console.log(`File changed: ${path}`); });
const fs = require('fs'); fs.watch('.', { recursive: true }, (eventType, filename) => { console.log(`File changed: ${filename}`); });
| Pattern | CPU Usage | Memory Usage | Event Reliability | Verdict |
|---|---|---|---|---|
| fs.watch recursive on large dirs | High | Moderate | Unreliable under load | [X] Bad |
| Chokidar with ignored patterns | Low | Low | Reliable | [OK] Good |