Tired of wasting gigabytes of Time Machine storage to node_modules folders?

Time Machine supports setting a sticky extended attribute on folders to exclude them from backups.

It works great, and I believe NPM should support it.

I opened an NPM RFC and would love your comments on it: https://github.com/npm/rfcs/pull/857/changes

In the mean time, you can easily set the bit w/ a command like:

xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd /path/to/node_modules/

Let’s do this!

On macOS, you can find the current summed size of your node_modules w/ this one-liner:

find /some/path/ -type d -name node_modules -prune -print0 2>/dev/null | xargs -0 du -sk 2>/dev/null | awk '{s+=$1} END {printf "%.2f GB\n", s/1048576}'

I have 7GB of node_modules. And that’s on a machine on which I recently deleted a lot of legacy JS projects I don’t need anymore.

@sindresorhus I’m thinking you maybe might relate?
GitHub - stevegrunwell/asimov: Automatically exclude development dependencies from Apple Time Machine backups

Automatically exclude development dependencies from Apple Time Machine backups - stevegrunwell/asimov

GitHub

@holtwick Nice! I have hesitated to do something like this, but having a script periodically traverse the whole file system breaks my heart a bit 😅.

It should be the package manager’s job to do this. e.g. Rust cargo already does https://github.com/rust-lang/cargo/pull/4386

Exclude target directory from Time Machine by kornelski · Pull Request #4386 · rust-lang/cargo

Fixes #3884

GitHub

@meego I agree 100%! Great effort! Hope it get's through.

I referenced your PR at PNPM, which I use mostly ;)
https://github.com/pnpm/pnpm/issues/6440

node_module excluded from MacOS TimeMachine backup with extended attribute · Issue #6440 · pnpm/pnpm

I'd be willing to implement this feature (contributing guide) Describe the user story As a developer working on a macOS computer, I want to ensure that all node_module folders created as part of th...

GitHub
@meego Does Time Machine exclude .git directories? If not, how do I tell it to ignore them?

@wigging No, Time Machine excludes very few directories by default.

You can use the xattr command mentioned earlier, or tmutil addexclusion (its man page is worth a read). For something more definitive that handles newly created .git folders, maybe a git alias in your shell on git clone/checkout?