macOS Time Machine exclusions can be managed via the terminal, as documented in Exclude folders by regex (?) from time machine backup, Control Time Machine from the command line, and Scripting Timemachine exclusion lists:
find `pwd` -maxdepth 3 -type d -name 'node_modules' | xargs -n 1 tmutil addexclusion
But this doesn’t make it show up in the System Preferences GUI. Writing to defaults
seems to do that:
sudo defaults write /Library/Preferences/com.apple.TimeMachine.plist SkipPaths -array-add "~/.cache"
but I’m too paranoid about doing it wrong to see what happens.
Asimov is another option (installed via homebrew) to “Automatically exclude development dependencies from Apple Time Machine backups”.
Improve.