Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active March 23, 2016 20:07
Show Gist options
  • Save ramiabraham/1b5a3d77b8814f62d9bf to your computer and use it in GitHub Desktop.
Save ramiabraham/1b5a3d77b8814f62d9bf to your computer and use it in GitHub Desktop.
node_modules sanity

###npm sanity

Does running npm install on a new project take a long time on your system?

Few things will wrangle high install/build times for node modules better than following this rule:

  1. Each time you npm install a project you're working on, take note of the npm modules that are installed into /node_modules. You can tail to a log file when running npm install, or you can open the /node_modules sub-directory within your project to see a list of everything that was installed.
  2. For each of the modules installed there, install them globally instead, so that they don't have to be installed per-project every time. You can install a package from npm globally by using the global flag -g.

Example: npm install -g package-name

Here's an example that will copy the name of every node module in the project to your clipboard (OSX*). In your project root, enter:

find node_modules -type d | pbcopy

Tedious? Definitely. But you'll only have to do it once.

Congrats! Now your build times are 30 seconds instead of MAX_INT minutes.


*If using Linux, you'll need to use xclip, or a similar library instead of pbcopy.

Cool Fact Corner:

This housekeeping method applies to most package managers.

@jennschiffer
Copy link

does this apply to npm 3 where all node module deps are "hoisted" to the root of node_modules

@ramiabraham
Copy link
Author

so I thought the hoisting features were system-wide, between the 3.0+ updates and dedupe, and that it'd handle things and maximize the lowest-possible redundancy. But I was entirely shitswaggled when I discovered countless module/dep dupes all over the place, hella redundant.

Internal dep structures within each project seem to be light years better for me since updating, though.

@jennschiffer
Copy link

:shitswaggled emoji:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment