\begin{quote}
A neat wrapper around node.\+js fs.\+watch / fs.\+watch\+File / FSEvents. \end{quote}
\href{https://www.npmjs.com/package/chokidar}{\texttt{ }}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33444}{}\doxysection{Why?}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33444}
Node.\+js {\ttfamily fs.\+watch}\+:


\begin{DoxyItemize}
\item Doesn\textquotesingle{}t report filenames on Mac\+OS.
\item Doesn\textquotesingle{}t report events at all when using editors like Sublime on Mac\+OS.
\item Often reports events twice.
\item Emits most changes as {\ttfamily rename}.
\item Has \href{https://github.com/nodejs/node/search?q=fs.watch&type=Issues}{\texttt{ a lot of other issues}}
\item Does not provide an easy way to recursively watch file trees.
\end{DoxyItemize}

Node.\+js {\ttfamily fs.\+watch\+File}\+:


\begin{DoxyItemize}
\item Almost as bad at event handling.
\item Also does not provide any recursive watching.
\item Results in high CPU utilization.
\end{DoxyItemize}

Chokidar resolves these problems.

Initially made for {\bfseries{\href{http://brunch.io}{\texttt{ Brunch}}}} (an ultra-\/swift web app build tool), it is now used in \href{https://github.com/gulpjs/gulp/}{\texttt{ gulp}}, \href{http://karma-runner.github.io}{\texttt{ karma}}, \href{https://github.com/Unitech/PM2}{\texttt{ PM2}}, \href{http://browserify.org/}{\texttt{ browserify}}, \href{http://webpack.github.io/}{\texttt{ webpack}}, \href{http://www.browsersync.io/}{\texttt{ Browser\+Sync}}, \href{https://github.com/microsoft/vscode}{\texttt{ Microsoft\textquotesingle{}s Visual Studio Code}}, and \href{https://www.npmjs.org/browse/depended/chokidar/}{\texttt{ many others}}. It has proven itself in production environments.\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33445}{}\doxysection{How?}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33445}
Chokidar does still rely on the Node.\+js core {\ttfamily fs} module, but when using {\ttfamily fs.\+watch} and {\ttfamily fs.\+watch\+File} for watching, it normalizes the events it receives, often checking for truth by getting file stats and/or dir contents.

On Mac\+OS, chokidar by default uses a native extension exposing the Darwin {\ttfamily FSEvents} API. This provides very efficient recursive watching compared with implementations like {\ttfamily kqueue} available on most $\ast$nix platforms. Chokidar still does have to do some work to normalize the events received that way as well.

On other platforms, the {\ttfamily fs.\+watch}-\/based implementation is the default, which avoids polling and keeps CPU usage down. Be advised that chokidar will initiate watchers recursively for everything within scope of the paths that have been specified, so be judicious about not wasting system resources by watching much more than needed.\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33446}{}\doxysection{Getting started}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33446}
Install with npm\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install chokidar }

\end{DoxyCode}


Then {\ttfamily require} and use it in your code\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var chokidar = require('chokidar');}
\DoxyCodeLine{}
\DoxyCodeLine{// One-\/liner for current directory, ignores .dotfiles}
\DoxyCodeLine{chokidar.watch('.', \{ignored: /(\string^|[\(\backslash\)/\(\backslash\)\(\backslash\)])\(\backslash\)../\}).on('all', (event, path) => \{}
\DoxyCodeLine{  console.log(event, path);}
\DoxyCodeLine{\}); }

\end{DoxyCode}



\begin{DoxyCode}{0}
\DoxyCodeLine{// Example of a more typical implementation structure:}
\DoxyCodeLine{}
\DoxyCodeLine{// Initialize watcher.}
\DoxyCodeLine{var watcher = chokidar.watch('file, dir, glob, or array', \{}
\DoxyCodeLine{  ignored: /(\string^|[\(\backslash\)/\(\backslash\)\(\backslash\)])\(\backslash\)../,}
\DoxyCodeLine{  persistent: true}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// Something to use when events are received.}
\DoxyCodeLine{var log = console.log.bind(console);}
\DoxyCodeLine{// Add event listeners.}
\DoxyCodeLine{watcher}
\DoxyCodeLine{  .on('add', path => log(`File \$\{path\} has been added`))}
\DoxyCodeLine{  .on('change', path => log(`File \$\{path\} has been changed`))}
\DoxyCodeLine{  .on('unlink', path => log(`File \$\{path\} has been removed`));}
\DoxyCodeLine{}
\DoxyCodeLine{// More possible events.}
\DoxyCodeLine{watcher}
\DoxyCodeLine{  .on('addDir', path => log(`Directory \$\{path\} has been added`))}
\DoxyCodeLine{  .on('unlinkDir', path => log(`Directory \$\{path\} has been removed`))}
\DoxyCodeLine{  .on('error', error => log(`Watcher error: \$\{error\}`))}
\DoxyCodeLine{  .on('ready', () => log('Initial scan complete. Ready for changes'))}
\DoxyCodeLine{  .on('raw', (event, path, details) => \{}
\DoxyCodeLine{    log('Raw event info:', event, path, details);}
\DoxyCodeLine{  \});}
\DoxyCodeLine{}
\DoxyCodeLine{// 'add', 'addDir' and 'change' events also receive stat() results as second}
\DoxyCodeLine{// argument when available: http://nodejs.org/api/fs.html\#fs\_class\_fs\_stats}
\DoxyCodeLine{watcher.on('change', (path, stats) => \{}
\DoxyCodeLine{  if (stats) console.log(`File \$\{path\} changed size to \$\{stats.size\}`);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// Watch new files.}
\DoxyCodeLine{watcher.add('new-\/file');}
\DoxyCodeLine{watcher.add(['new-\/file-\/2', 'new-\/file-\/3', '**/other-\/file*']);}
\DoxyCodeLine{}
\DoxyCodeLine{// Get list of actual paths being watched on the filesystem}
\DoxyCodeLine{var watchedPaths = watcher.getWatched();}
\DoxyCodeLine{}
\DoxyCodeLine{// Un-\/watch some files.}
\DoxyCodeLine{watcher.unwatch('new-\/file*');}
\DoxyCodeLine{}
\DoxyCodeLine{// Stop watching.}
\DoxyCodeLine{watcher.close();}
\DoxyCodeLine{}
\DoxyCodeLine{// Full list of options. See below for descriptions. (do not use this example)}
\DoxyCodeLine{chokidar.watch('file', \{}
\DoxyCodeLine{  persistent: true,}
\DoxyCodeLine{}
\DoxyCodeLine{  ignored: '*.txt',}
\DoxyCodeLine{  ignoreInitial: false,}
\DoxyCodeLine{  followSymlinks: true,}
\DoxyCodeLine{  cwd: '.',}
\DoxyCodeLine{  disableGlobbing: false,}
\DoxyCodeLine{}
\DoxyCodeLine{  usePolling: true,}
\DoxyCodeLine{  interval: 100,}
\DoxyCodeLine{  binaryInterval: 300,}
\DoxyCodeLine{  alwaysStat: false,}
\DoxyCodeLine{  depth: 99,}
\DoxyCodeLine{  awaitWriteFinish: \{}
\DoxyCodeLine{    stabilityThreshold: 2000,}
\DoxyCodeLine{    pollInterval: 100}
\DoxyCodeLine{  \},}
\DoxyCodeLine{}
\DoxyCodeLine{  ignorePermissionErrors: false,}
\DoxyCodeLine{  atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)}
\DoxyCodeLine{\});}

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33447}{}\doxysection{API}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33447}
{\ttfamily chokidar.\+watch(paths, \mbox{[}options\mbox{]})}


\begin{DoxyItemize}
\item {\ttfamily paths} (string or array of strings). Paths to files, dirs to be watched recursively, or glob patterns.
\item {\ttfamily options} (object) Options object as defined below\+:
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33448}{}\doxysubsubsection{Persistence}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33448}

\begin{DoxyItemize}
\item {\ttfamily persistent} (default\+: {\ttfamily true}). Indicates whether the process should continue to run as long as files are being watched. If set to {\ttfamily false} when using {\ttfamily fsevents} to watch, no more events will be emitted after {\ttfamily ready}, even if the process continues to run.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33449}{}\doxysubsubsection{Path filtering}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33449}

\begin{DoxyItemize}
\item {\ttfamily ignored} (\href{https://github.com/es128/anymatch}{\texttt{ anymatch}}-\/compatible definition) Defines files/paths to be ignored. The whole relative or absolute path is tested, not just filename. If a function with two arguments is provided, it gets called twice per path -\/ once with a single argument (the path), second time with two arguments (the path and the \href{http://nodejs.org/api/fs.html\#fs_class_fs_stats}{\texttt{ {\ttfamily fs.\+Stats}}} object of that path).
\item {\ttfamily ignore\+Initial} (default\+: {\ttfamily false}). If set to {\ttfamily false} then {\ttfamily add}/{\ttfamily add\+Dir} events are also emitted for matching paths while instantiating the watching as chokidar discovers these file paths (before the {\ttfamily ready} event).
\item {\ttfamily follow\+Symlinks} (default\+: {\ttfamily true}). When {\ttfamily false}, only the symlinks themselves will be watched for changes instead of following the link references and bubbling events through the link\textquotesingle{}s path.
\item {\ttfamily cwd} (no default). The base directory from which watch {\ttfamily paths} are to be derived. Paths emitted with events will be relative to this.
\item {\ttfamily disable\+Globbing} (default\+: {\ttfamily false}). If set to {\ttfamily true} then the strings passed to {\ttfamily .watch()} and {\ttfamily .add()} are treated as literal path names, even if they look like globs.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33450}{}\doxysubsubsection{Performance}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33450}

\begin{DoxyItemize}
\item {\ttfamily use\+Polling} (default\+: {\ttfamily false}). Whether to use fs.\+watch\+File (backed by polling), or fs.\+watch. If polling leads to high CPU utilization, consider setting this to {\ttfamily false}. It is typically necessary to {\bfseries{set this to {\ttfamily true} to successfully watch files over a network}}, and it may be necessary to successfully watch files in other non-\/standard situations. Setting to {\ttfamily true} explicitly on Mac\+OS overrides the {\ttfamily use\+Fs\+Events} default. You may also set the CHOKIDAR\+\_\+\+USEPOLLING env variable to true (1) or false (0) in order to override this option.
\item {\itshape Polling-\/specific settings} (effective when {\ttfamily use\+Polling\+: true})
\begin{DoxyItemize}
\item {\ttfamily interval} (default\+: {\ttfamily 100}). Interval of file system polling. You may also set the CHOKIDAR\+\_\+\+INTERVAL env variable to override this option.
\item {\ttfamily binary\+Interval} (default\+: {\ttfamily 300}). Interval of file system polling for binary files. (\href{https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json}{\texttt{ see list of binary extensions}})
\end{DoxyItemize}
\item {\ttfamily use\+Fs\+Events} (default\+: {\ttfamily true} on Mac\+OS). Whether to use the {\ttfamily fsevents} watching interface if available. When set to {\ttfamily true} explicitly and {\ttfamily fsevents} is available this supercedes the {\ttfamily use\+Polling} setting. When set to {\ttfamily false} on Mac\+OS, {\ttfamily use\+Polling\+: true} becomes the default.
\item {\ttfamily always\+Stat} (default\+: {\ttfamily false}). If relying upon the \href{http://nodejs.org/api/fs.html\#fs_class_fs_stats}{\texttt{ {\ttfamily fs.\+Stats}}} object that may get passed with {\ttfamily add}, {\ttfamily add\+Dir}, and {\ttfamily change} events, set this to {\ttfamily true} to ensure it is provided even in cases where it wasn\textquotesingle{}t already available from the underlying watch events.
\item {\ttfamily depth} (default\+: {\ttfamily undefined}). If set, limits how many levels of subdirectories will be traversed.
\item {\ttfamily await\+Write\+Finish} (default\+: {\ttfamily false}). By default, the {\ttfamily add} event will fire when a file first appears on disk, before the entire file has been written. Furthermore, in some cases some {\ttfamily change} events will be emitted while the file is being written. In some cases, especially when watching for large files there will be a need to wait for the write operation to finish before responding to a file creation or modification. Setting {\ttfamily await\+Write\+Finish} to {\ttfamily true} (or a truthy value) will poll file size, holding its {\ttfamily add} and {\ttfamily change} events until the size does not change for a configurable amount of time. The appropriate duration setting is heavily dependent on the OS and hardware. For accurate detection this parameter should be relatively high, making file watching much less responsive. Use with caution.
\begin{DoxyItemize}
\item $\ast${\ttfamily options.\+await\+Write\+Finish} can be set to an object in order to adjust timing params\+:$\ast$
\item {\ttfamily await\+Write\+Finish.\+stability\+Threshold} (default\+: 2000). Amount of time in milliseconds for a file size to remain constant before emitting its event.
\item {\ttfamily await\+Write\+Finish.\+poll\+Interval} (default\+: 100). File size polling interval.
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33451}{}\doxysubsubsection{Errors}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33451}

\begin{DoxyItemize}
\item {\ttfamily ignore\+Permission\+Errors} (default\+: {\ttfamily false}). Indicates whether to watch files that don\textquotesingle{}t have read permissions if possible. If watching fails due to {\ttfamily EPERM} or {\ttfamily EACCES} with this set to {\ttfamily true}, the errors will be suppressed silently.
\item {\ttfamily atomic} (default\+: {\ttfamily true} if {\ttfamily use\+Fs\+Events} and {\ttfamily use\+Polling} are {\ttfamily false}). Automatically filters out artifacts that occur when using editors that use \char`\"{}atomic writes\char`\"{} instead of writing directly to the source file. If a file is re-\/added within 100 ms of being deleted, Chokidar emits a {\ttfamily change} event rather than {\ttfamily unlink} then {\ttfamily add}. If the default of 100 ms does not work well for you, you can override it by setting {\ttfamily atomic} to a custom value, in milliseconds.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33452}{}\doxysubsection{Methods \& Events}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33452}
{\ttfamily chokidar.\+watch()} produces an instance of {\ttfamily FSWatcher}. Methods of {\ttfamily FSWatcher}\+:


\begin{DoxyItemize}
\item {\ttfamily .add(path / paths)}\+: Add files, directories, or glob patterns for tracking. Takes an array of strings or just one string.
\item {\ttfamily .on(event, callback)}\+: Listen for an FS event. Available events\+: {\ttfamily add}, {\ttfamily add\+Dir}, {\ttfamily change}, {\ttfamily unlink}, {\ttfamily unlink\+Dir}, {\ttfamily ready}, {\ttfamily raw}, {\ttfamily error}. Additionally {\ttfamily all} is available which gets emitted with the underlying event name and path for every event other than {\ttfamily ready}, {\ttfamily raw}, and {\ttfamily error}.
\item {\ttfamily .unwatch(path / paths)}\+: Stop watching files, directories, or glob patterns. Takes an array of strings or just one string.
\item {\ttfamily .close()}\+: Removes all listeners from watched files.
\item {\ttfamily .get\+Watched()}\+: Returns an object representing all the paths on the file system being watched by this {\ttfamily FSWatcher} instance. The object\textquotesingle{}s keys are all the directories (using absolute paths unless the {\ttfamily cwd} option was used), and the values are arrays of the names of the items contained in each directory.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33453}{}\doxysection{CLI}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33453}
If you need a CLI interface for your file watching, check out \href{https://github.com/kimmobrunfeldt/chokidar-cli}{\texttt{ chokidar-\/cli}}, allowing you to execute a command on each change, or get a stdio stream of change events.\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33454}{}\doxysection{Install Troubleshooting}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33454}

\begin{DoxyItemize}
\item {\ttfamily npm WARN optional dep failed, continuing fsevents@n.\+n.\+n}
\begin{DoxyItemize}
\item This message is normal part of how {\ttfamily npm} handles optional dependencies and is not indicative of a problem. Even if accompanied by other related error messages, Chokidar should function properly.
\end{DoxyItemize}
\item {\ttfamily ERR! stack Error\+: Python executable \char`\"{}python\char`\"{} is v3.\+4.\+1, which is not supported by gyp.}
\begin{DoxyItemize}
\item You should be able to resolve this by installing python 2.\+7 and running\+: {\ttfamily npm config set python python2.\+7}
\end{DoxyItemize}
\item {\ttfamily gyp ERR! stack Error\+: not found\+: make}
\begin{DoxyItemize}
\item On Mac, install the XCode command-\/line tools
\end{DoxyItemize}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33455}{}\doxysection{License}\label{md_sfcode_node_modules_webpack_dev_server_node_modules_chokidar_README_autotoc_md33455}
The MIT License (MIT)

Copyright (c) 2012-\/2019 Paul Miller (\href{https://paulmillr.com}{\texttt{ https\+://paulmillr.\+com}}) \& Elan Shanker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “\+Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions\+:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “\+AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 