We all know that downloading dependencies with npm can be very time consuming, specially when we are limited to old npm versions.
For me, as a developer, this wasn't such a big deal because I had to do this very few times on my local development machine and everything worked with the node_modules cache in my project's folder. But now I want to take this the applications to a CI environment, with Jenkins.
I realized a huge ammount of time was spent on downloading dependencies with npm. This is a problem because:
npm downloads the dependencies in the project's folder, not a global folder such as Maven's /home/user/.m2
I have to clean up the Jenkins workspace folder in every run to avoid issues with the git checkout.
I want a very elegant solution for caching the npm dependencies on my Jenkins slaves, but so far I can only think of:
Removing everything but the node_modules folders from the Jenkins workspace. I don't like this because I could consume lots of HDD if I keep creating branches for my project. Each branch creates a workspace.
doing something like
cp ./node_modules /home/npm_cache
after every npm install and thencp /home/npm_cache ./node_modules
after the code checkout.
I feel these solutions are terrible. There must be a better way to do this.