9

Strange enough node.js unlikely maven installs the packages the software needs inside the project directory.

Is there a way to introduce a central repository which also caches different versions of components and would allow to pull them on build like we know it from other ecosystems?

4
  • 2
    The yarn replacement for npm from Facebook does have a global per-user cache just like Maven does. The node_modules folder is not a cache, it is used by the software as its dependencies store. Jun 27, 2017 at 7:39
  • just for curioisity, why wouldn't you place this as answer? (I would accept it). And, wouldn't npm -g allow for global package management as well, Maven-like? Jun 27, 2017 at 12:32
  • npm -g would "install" packages in the global namespace, this is not the same as caching. Caching has all the various versions of each specific package, and when you need to install that specific version - it would use the cache instead of downloading the source over the internet. Actually installing the package globally doesn't have this property. Jun 27, 2017 at 12:53
  • Didn't add this as the answer, since the question is very unclear to me. I don't understand exactly what the author wants to know, what you ask. Jun 27, 2017 at 12:53

1 Answer 1

6

Strange enough node.js unlikely maven installs the packages the software needs inside the project directory.

I don't see fundamental differences between npm on node.js and Maven. In both cases, the dependencies finally end up in the project directory (npm: /node_modules, Maven: /target). Otherwise, you cannot continue building the software. (When you run the build system to create the final artifact, it needs the dependencies.)

In addition, both have a global cache to avoid downloading already fetched dependencies: In Maven, the default cache directory is ~/.m2 (on Linux and MacOS). For npm, it is ~/.npm.

Is there a way to introduce a central repository which also caches different versions of components and would allow to pull them on build like we know it from other ecosystems?

If the system cache is not enough and you do not want to depend completely on the public repository (npm: registry.npmjs.org, Maven: Maven Central), you can run your own mirror. For instance, if you want to be able to rebuild the software even if the public repository is down.

In my previous job, we used Nexus as a caching proxy and local registry (for hosting code that is only accessible within your organization). It supports both npm (see documentation) and Maven (see documentation). (There are other tools, but the point is that both ecosystems can be handled by one tool.)

Of course, there are differences between Maven and npm. For instance, Maven is also a full build system, whereas the scope of npm is primarily dependency management. Maven also defines conventions to structure a Java project ("The Maven Way"). But when looking only at the dependency aspect, package managers for Node.js like npm are conceptually not so different from Maven.

1
  • 5
    Just a small correction: Maven doesn't copy the dependencies to the target folder. It builds its classpath from the cached artifacts in the local Maven repository.
    – eerriicc
    Feb 15, 2019 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.