npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Prevent Spotlight from indexing node_modules folders

Spotlight search on macOS is indexing all node_modules folders, resulting in unnecessarily bloated indexes. There is no way to define Spotlight exclusions by pattern (file name) — each exclusion must be individually added.

npm could avoid this by including a .metadata_never_index file in node_modules.

This issue has been brought up before, in the old repo: https://github.com/npm/npm/issues/15346


@isaacs Please consider this! For all the unfortunate folks with older/slower macs! Very easy, with great potential boost in performance :)


@isaacs still affects people learning to code who can’t afford better machines!


This is an interesting idea, but it might not be appropriate for npm to make the decision. The files in node_modules do contain searchable text, they aren’t just junk temporary files, or files only intended for non-human use. I agree the value of indexing is lower than with your own code, but I don’t think it is zero.

A complication is that platform specific files in potentially shared locations have the potential to upset people on platforms that don’t need or understand them.

A location where .metadata_never_index would be more compelling is the npm cache folder.

A simple low-tech option for people on slow Macs is to keep all your projects under one folder, and exclude that folder from indexing. I have done this myself in the past when I was noticing performance problems, decided that indexing code was not adding enough value.


You make some good points @shadowspawn. There is some value in indexing node_modules. Although the npm cache certainly less so. I wonder if it’s possible to create a postinstall script that would add this file on mac, so anybody else finding this thread via google can have their cake and eat it too.


An option in .npmrc would easily allow users to opt in to disabling spotlight indexing