How does NodeJS manage package.json in subfolders?

4

How does NodeJS manage packages.json in sub-folders?

You have your normal application but have sub-modules that you want to have your own dependencies, how does Node manage it? Does it create another node_modules and put all files back into that subfolder?

(Assume that it is an architecture error but ...), on the hypothetical idea that they had two dependencies of the same version both in the top package and in the packages of the subpackages they would have the same version replicated in both node_modules of the root folder and node_modules of the sub-folders?

Example:

└─── MinhaAplicacaoDeExemplo
    └───v1
        │--- package.json
        └─── node_modules
        │    └─── lodash1.0
        │
        │
        └─── sub-pasta-que-tem-os-proprios-modulos
           │--- package.json
           └─── node_modules
                └─── lodash1.0
    
asked by anonymous 27.11.2015 / 16:56

2 answers

0

In version 3.0 of NPM they corrected this problem: link

    
21.01.2016 / 17:03
1

Currently npm does not allow two versions of the same package, since in package.json packages are managed by name.

In the case of subfolders, npm does not manage them as if they were submodules, as git does, for example. Everything the npm plays is registered in package.json .

If you want to have different folders for modules that you want to use as a dependency on another module, use the link feature. of npm, which allows you to register folders as if they were packages to be installed on other projects.

    
17.12.2015 / 13:59