npm i sync-directory -g
syncdir ./src ./mirror -w
# or in a project
npm i sync-directorySync two directories without inventing another watcher.
sync-directory copies or hardlinks an entire source tree into a target folder. Use it once, or keep it running with chokidar watch. Default is copy, because it is the mode file watchers actually see.
Copy vs hardlink
copy is the default. It is slower, but the target files are real files, so most watchers fire.
hardlink is faster and uses almost no extra disk. Some watchers will not notice changes on the target side. Pick it when you control both trees.
See the comparison if you are coming from rsync or a homegrown fs-extra loop.
Watch
Pass watch: true (API) or -w (CLI). Under the hood this is chokidar. You get a watcher back from the sync API.
Filter
exclude skips paths. forceSync always wins, so you can keep node_modules out except one package.
Sync or async
syncDirectory.sync() blocks. syncDirectory.async() returns a Promise and can await afterEachSync.