Is there a way to globally ignore folders with a certain name (say node_modules)

I know I can do it manually for each instance but I was wondering if its possible to just let spotlight know not to index these folders? node_modules, for example, typically has thousands of files that I don't want to search and it ends up slowing down spotlight.

I've looked around but I can only find answers that suggest manually adding folders in spotlight privacy list. Does someone have a better, glob way to it?

  • 1
    Adding specific folders to the Spotlight privacy is the way to have it ignore during indexing. Why are you against doing it the Apple-provided way?
    – fsb
    Commented Jul 24, 2016 at 3:29
  • 14
    Because I want to ignore many instances of this folder and doing that "the apple-provided way" will be time-consuming and ineffective (I might miss some). In addition to that, whenever a new node_modules folder is created, I'll have to go and add it manually.
    – MayThrow
    Commented Jul 24, 2016 at 3:35
  • See also apple.stackexchange.com/questions/87090/…
    – mems
    Commented Jun 6, 2017 at 17:20
  • Everyone facing this issue, please submit a request to apple.com/feedback/macos.html so they'll do something about it!
    – Andy
    Commented Nov 17, 2020 at 0:30
  • For anyone who has a similar problem, the solution for me was just having a single location under which I do all my node stuff. I know, pretty obvious in hindsight. Specifically, I created a separate case-sensitive volume for work and ignored that entire volume in Spotlight privacy settings. You won't be able to jump to project files using Spotlight of course but that's a fair tradeoff IMO.
    – MayThrow
    Commented May 20 at 10:33

3 Answers 3


There is no known method to exclude from Spotlight a file or a folder based on a pattern (ex.: its name).

However it's possible to exclude a folder from Spotlight by adding to it an empty file .metadata_never_index.

You can use this method to ignore all node_moduleand bower_modules folders:

find /path/to/projects -type d  -path '*node_modules/*' -prune -o -type d -name 'node_modules' -exec touch '{}/.metadata_never_index' \;


It look like the method .metadata_never_index is ignored by Spotlight since Mojave.

Edit 2:

As @JohnLee pointed it out, the extended attribute com.apple.metadata:com_apple_backup_excludeItem is not related / doesn't have any impact on Spotlight.

However *.noindex and symlink aren't indexed by mds (the backend of Spotlight). You can use it as band-aid:

# Rename all node_modules to node_modules.noindex and create a symlink node_modules -> node_modules.noindex
find /path/to/projects -type d \( -path '*node_modules/*' -o -path '*node_module.noindex/*' \) -prune -o -type d -name 'node_modules' -exec mv '{}' '{}.noindex' \; -exec ls -s '{}.noindex' '{}' \;

Note: if you use npm-ci, the node_modules is "automatically removed before npm ci begins its install".

  • 6
    I cannot confirm that this works for my Mac with Sierra as of today. I ran the script and can find all the hidden .metadata_never_index files in my node_modules, yet after a forced refresh of the spotlight index, the files are still being indexed. There is also a node_modules NPM Github PR open but I am afraid that this won't be the final solution to the problem github.com/npm/npm/issues/15346 Commented Jun 5, 2017 at 16:59
  • Note: Chrome and Opera use it for profile folder. See bugs.chromium.org/p/chromium/issues/detail?id=395300#c5
    – mems
    Commented Jun 6, 2017 at 17:14
  • 6
    Sadly .metadata_never_index is not honored on mojave.
    – Karl Pokus
    Commented Sep 4, 2019 at 11:51
  • @mems the linked article talks about it being excluded from backups, but doesn't talk about Spotlight. Do you have a source that talks about it in relation to Spotlight?
    – John Lee
    Commented Nov 6, 2020 at 23:39
  • @JohnLee you right, it's an attribute used by TimeMachine to exlude files, not Spotlight
    – mems
    Commented Nov 8, 2020 at 18:47

In case anyone missed fsb's comment in the question, as I did. Apple provides a privacy tab in the Spotlight settings.

Goto "System Preferences" > "Spotlight" > "Privacy" > "+" Add folders to the list.

Note: This may not work immediately, I had to restart Spotlight to see the effects.

  • 1
    Hi I wonder how to restart spotlight?
    – ch271828n
    Commented Aug 4, 2022 at 10:21

Apparently adding '.noindex' to a parent folder name will prevent Spotlight from indexing.

NB: I haven't personally verified.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .