How does Nodejs manage package.json in sub-folders?

Asked

Viewed 220 times

5

How Nodejs manages Packages.json in sub-folders?

You have your normal application but you have sub-modules that you want to have your own dependencies, how does Node manage it? It creates another one node_modules and puts all the files back inside that sub-folder?

(Suppose it is an architecture error but...), in the hypothetical idea that they had two dependencies of the same version both in the top package and in the subpackage Packages they would have the same version replicated both in the node_modules of the root stock as in node_modules of sub-folders?

Example:

└─── MinhaAplicacaoDeExemplo
    └───v1
        │--- package.json
        └─── node_modules
        │    └─── lodash1.0
        │
        │
        └─── sub-pasta-que-tem-os-proprios-modulos
           │--- package.json
           └─── node_modules
                └─── lodash1.0
  • Have two versions of the same package on package.json is a long discussion that has been active in NPM: https://github.com/npm/npm/issues/5499

2 answers

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 npm touches is recorded 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 functionality of link npm, which allows you to register folders as if they were packages to be installed in other projects.

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.