Làm thế nào để tìm thư mục npm?

Được cung cấp bởi. npm_5. 8. 0+ds6-4_all foo@1.2.3 will install to the sensible root of your package, even if you happen to have cded into some other folder. Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. [This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.] If no package root is found, then the current folder is used. When you run npm install foo@1.2.3, then the package is loaded into the cache, and then unpacked into ./node_modules/foo. Then, any of foo's dependencies are similarly unpacked into ./node_modules/foo/node_modules/.... Any bin files are symlinked to ./node_modules/.bin/, so that they may be found by npm scripts when necessary. Global Installation If the global configuration is set to true, then npm will install packages "globally". For global installation, packages are installed roughly the same way, but using the folders described above. Cycles, Conflicts, and Folder Parsimony Cycles are handled using the property of node's module system that it walks up the directories looking for node_modules folders. So, at every stage, if a package is already installed in an ancestor node_modules folder, then it is not installed at the current location. Consider the case above, where foo -> bar -> baz. Imagine if, in addition to that, baz depended on bar, so you'd have: foo -> bar -> baz -> bar -> baz .... However, since the folder structure is: foo/node_modules/bar/node_modules/baz, there's no need to put another copy of bar into .../baz/node_modules, since when it calls require["bar"], it will get the copy that is installed in foo/node_modules/bar. This shortcut is only used if the exact same version would be installed in multiple nested node_modules folders. It is still possible to have a/node_modules/b/node_modules/a if the two "a" packages are different versions. However, without repeating the exact same package multiple times, an infinite regress will always be prevented. Another optimization can be made by installing dependencies at the highest level possible, below the localized "target" folder. Example Consider this dependency graph: foo +-- blerg@1.2.5 +-- bar@1.2.3 | +-- blerg@1.x [latest=1.3.7] | +-- baz@2.x | | `-- quux@3.x | | `-- bar@1.2.3 [cycle] | `-- asdf@* `-- baz@1.2.3 `-- quux@3.x `-- bar In this case, we might expect a folder structure like this: foo +-- node_modules +-- blerg [1.2.5] baz [D], quux's [E] folder tree is empty, because its dependency on bar is satisfied by the parent folder copy installed at [B]. For a graphical breakdown of what is installed where, use npm ls. Publishing Upon publishing, npm will look in the node_modules folder. If any of the items there are not in the bundledDependencies array, then they will not be included in the package tarball. This allows a package maintainer to install all of their dependencies [and dev dependencies] locally, but only re-publish those items that cannot be found elsewhere. See npm help 5 package.json for more information.

XEM THÊM

       · npm help 5 package.json

       · npm help install

       · npm help pack

       · npm help cache

       · npm help config

       · npm help 5 npmrc

       · npm help 7 config

       · npm help publish

                                          February 2019                            NPM-FOLDERS[5]

Thư mục npm nằm ở đâu?

Cấu hình tiền tố mặc định cho vị trí cài đặt nút. Trên hầu hết các hệ thống, đây là /usr/local . Trên Windows, đó là %AppData%\npm. Trên các hệ thống Unix, nó tăng một cấp, vì nút thường được cài đặt tại {prefix}/bin/node thay vì {prefix}/node. người cũ.

Npm của tôi được cài đặt ở đâu?

Cài đặt gói cục bộ. Các gói cục bộ được cài đặt trong thư mục nơi bạn chạy npm install và chúng được đặt trong thư mục node_modules trong thư mục này.

Mô-đun nút nằm ở đâu?

Trên các hệ thống Unix, chúng thường được đặt trong /usr/local/lib/node hoặc /usr/local/lib/node_modules khi được cài đặt trên toàn cầu. If you set the NODE_PATH environment variable to this path, the modules can be found by node. Non-global libraries are installed the node_modules sub folder in the folder you are currently in.

Chủ Đề