Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid downloading node JS modules over and over for all projects

I am learning NodeJS and Electron app dev and currently every sample app I work on has me run the command npm install which results in the node_modules downloading to the project folder. This results in a really large amount of disk usage as many app use the same node modules over and over.

Is there a way to install all the required node modules for all projects to a central location and make them all use that 1 source of modules?


UPDATE

Another concern of mine. If the Electron apps I am building are packaged as an install-able .exe file. Will they be able to package the functionality needed from those global Node packages wwhen the app is ran on another users PC?

like image 479
JasonDavis Avatar asked Jan 23 '26 20:01

JasonDavis


1 Answers

There are two ways to install npm packages: locally or globally. To download packages globally, you simply use the command npm install -g This is recommended if you want to use module as a command line tool.


UPDATE

You can always use: npm link (in package dir) and npm link [<@scope>/]<pkg>[@<version>] which will install module on your disk only once and every additional time will just make symlink to that module.

like image 128
Lkraljevic Avatar answered Jan 25 '26 10:01

Lkraljevic