Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Gulp Basics Gulp your JavaScript Workflow Using Third Party Gulp Libraries

Ratik Sharma
Ratik Sharma
32,885 Points

Why does npm take so long while installing packages?

I have a decent internet connection but every time I install a package via npm (be it gulp or gulp-concat), it takes ~5 minutes to download and install. Why is this happening? Are these node packages large in size? If not, Can I increase the speed in any way?

Also, I don't see any verbose logging while the package downloads. I only see the '/' rotating for indicating an ongoing process. Is that the default behaviour?

3 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

it takes ~5 minutes to download and install. Why is this happening? Are these node packages large in size?

Node Modules sometimes have many dependencies (other modules that are needed to run correctly). Often these dependent modules are used for different modules which may be used in your package.json so when they are downloaded/ installed multiple copies will be installed for each modules that requires them. This may seem verbose, but the reasoning is to separate concerns and to allow each module still able to function correctly. This means that individual modules, particularly those with other modules as dependencies, install each as needed. This is also following a fundamental idiom of programming for packaging, which has it's root in *nix, is to do one task, keep it DRY, and do it well.

If you happen to explore the node_modules directory after doing an npm install command, you will typically see many sub-directories for each module.

Installing modules globally may help here, but it will not help very much if you are planning to share what you create.

Also, I don't see any verbose logging while the package downloads. I only see the '/' rotating for indicating an ongoing process. Is that the default behaviour?

Yes it is, unless there is an error.

Tip:

By disabling the npm install progress bar during downloads, you can significantly cut down on download times. I've experienced up to two times (50%) faster download many times & on average one-third (30%) faster download times.

npm set progress=false
Sean T. Unwin
Sean T. Unwin
28,690 Points

Cool tip and interesting anecdotes, Clifford Fajardo . Thanks for sharing.

I recommend that you can use Yarn.You can look the differences between Yarn and npm in this essay and learn how to migrate from NPM to Yarn in Migrating from npm