Stop Indexing node_modules! 😱

oculus42

Samuel Rouse

Posted on June 28, 2024

Stop Indexing node_modules! 😱

Running npm install (or npm ci) can add tens of thousands of files to your computer in the node_modules folder. These new files will trigger a search indexer, which reads every one of those files and add them to the search index. That adds up to a lot of lost system performance.

Users can also expect security software to add to the performance cost, as every file access may trigger or even wait for one or more security packages to perform threat assessment.

You probably don't want to search node_modules folders from in your OS, nor do you want their contents to show up in searches. You might wander into node_modules intentionally on occasion, but you're much more likely to do this in your editor/IDE.

Exclude From Indexing

So save yourself the trouble and disable indexing on these folders!
You can isolate each node_modules folder separately, or, if you are like me, exclude the folder containing all of your repositories from indexing. My IDE provides fast indexed searching, and I rarely need to search for code at the OS level, so one entry saves me a lot of time.

macOS

  1. Open System Settings.
  2. Choose Siri & Spotlight.
  3. At the bottom, click Spotlight Privacy…
  4. Click the Plus (+) button at the bottom of the list and select a folder you want to exclude.
  5. Repeat for all the folders you want.

macOS System Settings, Siri & Spotlight, Spotlight Privacy

Windows

  1. Open Settings.
  2. Choose Privacy & security.
  3. Click Searching Windows.
  4. Under Exclude folders from enhanced search, click Add an excluded folder.
  5. Repeat for all the folders you want.

Windows Settings, Privacy & security, Searching Windows

Enjoy!

That's it! Experience extra performance, less heat and improved battery life, and enjoy getting some of that computer performance back.

Side Quests

More folders

You might consider excluding the central npm package cache, or other folders that see a lot of updates or churn. The fewer cycles your system wastes on indexing files you will never search for, the more it has available for you!

Package Managers

You might save even more time, energy, and disk space using a package manager like pNPM, where the packages are added using file-system links rather than many duplicate fresh package installs. Then exclude the pNPM cache from indexing, too!


Header image created with DALL-E 3 through Microsoft Copilot Designer

💖 💪 🙅 🚩
oculus42
Samuel Rouse

Posted on June 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related