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:
/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
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.