I have a list of websites like this:
project1/site
project2/site
project4/site
...
projectN/site
Each site
folder has inside node_modules
folder, gruntfile.js
file and a package.json
file. So they look like this:
project1/site/gruntfile.js
project1/site/package.json
project1/site/node_modules/
...
projectN/site/gruntfile.js
projectN/site/package.json
projectN/site/node_modules/
Everything is working fine with my tasks, plugins and stuff.
I am wondering if I can work this out with just one node_modules
folder on my root folder as my websites are using similar tasks.
project1/site/
project2/site/
...
projectN/site/
/node_modules/
Is this even possible? What do I need to do?
We do not need to install a module every time when installed globally. It takes less memory as only one copy is installed. We can make . js scripts and run them anywhere without having a node_modules folder in the same directory when packages are installed globally.
Yes you can copy whole node_modules (have done it multiple times) from one project to another and use same package. json and package-lock (Will only save time in dependencies installation/download)
While doing npm install, inside node_modules . staging folder is getting created. Reasons: This is a temporary folder where the modules will be kept untill npm downloads all the modules specified in the package. json.
You can use the -g
flag with npm
to install modules globally, as in:
npm install -g <modulename>
This will install all the modules so they are accessible to all your node projects.
And then you can create a link for each of the projects to the required modules using npm link
, as explained in the link @jakerella referred to:
...there are some cases where you want to do both. Coffee-script and Express both are good examples of apps that have a command line interface, as well as a library. In those cases, you can do one of the following:
- Install it globally, and then npm link coffee-script or npm link express (if you’re on a platform that supports symbolic links.) Then you only need to update the global copy to update all the symlinks as well.
See the npm documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With