Stop Apple Spotlight from slowing down your Mac by preventing it to index node_modules folders

Written by / Original link on Aug. 27, 2019


Speaking of node_modules folders, this tip by Roel Van Gils came to mind:

Hat tip, Roel! But wait dear reader, there’s more …


In case you want to retroactively add .metadata_never_index files to your node_modules folders, use this command as suggested by @malfaitrobin (a former student of mine):

$ find . -type d -name "node_modules" -exec touch "{}/.metadata_never_index" \;

You might need to reindex Spotlight after this before it takes effect:

$ sudo mdutil -i on /


To stay ahead of things, it’d be much better to create this .metadata_never_index file before running npm install.

As nor npm install (issue) nor yarn install (issue) have the creation of said file integrated, I use a preinstall script that does the job for me.

To enable it, add the line(s) below to your package.json:

"scripts": {
  "preinstall": "mkdir -p ./node_modules && touch ./node_modules/.metadata_never_index"

The preinstall script will be run right before npm install does its thing, ensuring the presence of the .metadata_never_index file inside ./node_modules 1f642.png

Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

2615.png Buy me a Coffee ($3)

node-modules spotlight calevans link original-content bram

« Star Wars: The Rise Of Skywalker (D23 Special Look) - Abstracting API calls with Symfony serializer »