]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/man/man5/npm-folders.5
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / man / man5 / npm-folders.5
1 .TH "NPM\-FOLDERS" "5" "October 2016" "" ""
2 .SH "NAME"
3 \fBnpm-folders\fR \- Folder Structures Used by npm
4 .SH DESCRIPTION
5 .P
6 npm puts various things on your computer\.  That's its job\.
7 .P
8 This document will tell you what it puts where\.
9 .SS tl;dr
10 .RS 0
11 .IP \(bu 2
12 Local install (default): puts stuff in \fB\|\./node_modules\fP of the current
13 package root\.
14 .IP \(bu 2
15 Global install (with \fB\-g\fP): puts stuff in /usr/local or wherever node
16 is installed\.
17 .IP \(bu 2
18 Install it \fBlocally\fR if you're going to \fBrequire()\fP it\.
19 .IP \(bu 2
20 Install it \fBglobally\fR if you're going to run it on the command line\.
21 .IP \(bu 2
22 If you need both, then install it in both places, or use \fBnpm link\fP\|\.
23
24 .RE
25 .SS prefix Configuration
26 .P
27 The \fBprefix\fP config defaults to the location where node is installed\.
28 On most systems, this is \fB/usr/local\fP\|\. On windows, this is the exact
29 location of the node\.exe binary\.  On Unix systems, it's one level up,
30 since node is typically installed at \fB{prefix}/bin/node\fP rather than
31 \fB{prefix}/node\.exe\fP\|\.
32 .P
33 When the \fBglobal\fP flag is set, npm installs things into this prefix\.
34 When it is not set, it uses the root of the current package, or the
35 current working directory if not in a package already\.
36 .SS Node Modules
37 .P
38 Packages are dropped into the \fBnode_modules\fP folder under the \fBprefix\fP\|\.
39 When installing locally, this means that you can
40 \fBrequire("packagename")\fP to load its main module, or
41 \fBrequire("packagename/lib/path/to/sub/module")\fP to load other modules\.
42 .P
43 Global installs on Unix systems go to \fB{prefix}/lib/node_modules\fP\|\.
44 Global installs on Windows go to \fB{prefix}/node_modules\fP (that is, no
45 \fBlib\fP folder\.)
46 .P
47 Scoped packages are installed the same way, except they are grouped together
48 in a sub\-folder of the relevant \fBnode_modules\fP folder with the name of that
49 scope prefix by the @ symbol, e\.g\. \fBnpm install @myorg/package\fP would place
50 the package in \fB{prefix}/node_modules/@myorg/package\fP\|\. See npm help 7 \fBscope\fP for
51 more details\.
52 .P
53 If you wish to \fBrequire()\fP a package, then install it locally\.
54 .SS Executables
55 .P
56 When in global mode, executables are linked into \fB{prefix}/bin\fP on Unix,
57 or directly into \fB{prefix}\fP on Windows\.
58 .P
59 When in local mode, executables are linked into
60 \fB\|\./node_modules/\.bin\fP so that they can be made available to scripts run
61 through npm\.  (For example, so that a test runner will be in the path
62 when you run \fBnpm test\fP\|\.)
63 .SS Man Pages
64 .P
65 When in global mode, man pages are linked into \fB{prefix}/share/man\fP\|\.
66 .P
67 When in local mode, man pages are not installed\.
68 .P
69 Man pages are not installed on Windows systems\.
70 .SS Cache
71 .P
72 See npm help \fBnpm\-cache\fP\|\.  Cache files are stored in \fB~/\.npm\fP on Posix, or
73 \fB~/npm\-cache\fP on Windows\.
74 .P
75 This is controlled by the \fBcache\fP configuration param\.
76 .SS Temp Files
77 .P
78 Temporary files are stored by default in the folder specified by the
79 \fBtmp\fP config, which defaults to the TMPDIR, TMP, or TEMP environment
80 variables, or \fB/tmp\fP on Unix and \fBc:\\windows\\temp\fP on Windows\.
81 .P
82 Temp files are given a unique folder under this root for each run of the
83 program, and are deleted upon successful exit\.
84 .SH More Information
85 .P
86 When installing locally, npm first tries to find an appropriate
87 \fBprefix\fP folder\.  This is so that \fBnpm install foo@1\.2\.3\fP will install
88 to the sensible root of your package, even if you happen to have \fBcd\fPed
89 into some other folder\.
90 .P
91 Starting at the $PWD, npm will walk up the folder tree checking for a
92 folder that contains either a \fBpackage\.json\fP file, or a \fBnode_modules\fP
93 folder\.  If such a thing is found, then that is treated as the effective
94 "current directory" for the purpose of running npm commands\.  (This
95 behavior is inspired by and similar to git's \.git\-folder seeking
96 logic when running git commands in a working dir\.)
97 .P
98 If no package root is found, then the current folder is used\.
99 .P
100 When you run \fBnpm install foo@1\.2\.3\fP, then the package is loaded into
101 the cache, and then unpacked into \fB\|\./node_modules/foo\fP\|\.  Then, any of
102 foo's dependencies are similarly unpacked into
103 \fB\|\./node_modules/foo/node_modules/\.\.\.\fP\|\.
104 .P
105 Any bin files are symlinked to \fB\|\./node_modules/\.bin/\fP, so that they may
106 be found by npm scripts when necessary\.
107 .SS Global Installation
108 .P
109 If the \fBglobal\fP configuration is set to true, then npm will
110 install packages "globally"\.
111 .P
112 For global installation, packages are installed roughly the same way,
113 but using the folders described above\.
114 .SS Cycles, Conflicts, and Folder Parsimony
115 .P
116 Cycles are handled using the property of node's module system that it
117 walks up the directories looking for \fBnode_modules\fP folders\.  So, at every
118 stage, if a package is already installed in an ancestor \fBnode_modules\fP
119 folder, then it is not installed at the current location\.
120 .P
121 Consider the case above, where \fBfoo \-> bar \-> baz\fP\|\.  Imagine if, in
122 addition to that, baz depended on bar, so you'd have:
123 \fBfoo \-> bar \-> baz \-> bar \-> baz \.\.\.\fP\|\.  However, since the folder
124 structure is: \fBfoo/node_modules/bar/node_modules/baz\fP, there's no need to
125 put another copy of bar into \fB\|\.\.\./baz/node_modules\fP, since when it calls
126 require("bar"), it will get the copy that is installed in
127 \fBfoo/node_modules/bar\fP\|\.
128 .P
129 This shortcut is only used if the exact same
130 version would be installed in multiple nested \fBnode_modules\fP folders\.  It
131 is still possible to have \fBa/node_modules/b/node_modules/a\fP if the two
132 "a" packages are different versions\.  However, without repeating the
133 exact same package multiple times, an infinite regress will always be
134 prevented\.
135 .P
136 Another optimization can be made by installing dependencies at the
137 highest level possible, below the localized "target" folder\.
138 .SS Example
139 .P
140 Consider this dependency graph:
141 .P
142 .RS 2
143 .nf
144 foo
145 +\-\- blerg@1\.2\.5
146 +\-\- bar@1\.2\.3
147 |   +\-\- blerg@1\.x (latest=1\.3\.7)
148 |   +\-\- baz@2\.x
149 |   |   `\-\- quux@3\.x
150 |   |       `\-\- bar@1\.2\.3 (cycle)
151 |   `\-\- asdf@*
152 `\-\- baz@1\.2\.3
153     `\-\- quux@3\.x
154         `\-\- bar
155 .fi
156 .RE
157 .P
158 In this case, we might expect a folder structure like this:
159 .P
160 .RS 2
161 .nf
162 foo
163 +\-\- node_modules
164     +\-\- blerg (1\.2\.5) <\-\-\-[A]
165     +\-\- bar (1\.2\.3) <\-\-\-[B]
166     |   `\-\- node_modules
167     |       +\-\- baz (2\.0\.2) <\-\-\-[C]
168     |       |   `\-\- node_modules
169     |       |       `\-\- quux (3\.2\.0)
170     |       `\-\- asdf (2\.3\.4)
171     `\-\- baz (1\.2\.3) <\-\-\-[D]
172         `\-\- node_modules
173             `\-\- quux (3\.2\.0) <\-\-\-[E]
174 .fi
175 .RE
176 .P
177 Since foo depends directly on \fBbar@1\.2\.3\fP and \fBbaz@1\.2\.3\fP, those are
178 installed in foo's \fBnode_modules\fP folder\.
179 .P
180 Even though the latest copy of blerg is 1\.3\.7, foo has a specific
181 dependency on version 1\.2\.5\.  So, that gets installed at [A]\.  Since the
182 parent installation of blerg satisfies bar's dependency on \fBblerg@1\.x\fP,
183 it does not install another copy under [B]\.
184 .P
185 Bar [B] also has dependencies on baz and asdf, so those are installed in
186 bar's \fBnode_modules\fP folder\.  Because it depends on \fBbaz@2\.x\fP, it cannot
187 re\-use the \fBbaz@1\.2\.3\fP installed in the parent \fBnode_modules\fP folder [D],
188 and must install its own copy [C]\.
189 .P
190 Underneath bar, the \fBbaz \-> quux \-> bar\fP dependency creates a cycle\.
191 However, because bar is already in quux's ancestry [B], it does not
192 unpack another copy of bar into that folder\.
193 .P
194 Underneath \fBfoo \-> baz\fP [D], quux's [E] folder tree is empty, because its
195 dependency on bar is satisfied by the parent folder copy installed at [B]\.
196 .P
197 For a graphical breakdown of what is installed where, use \fBnpm ls\fP\|\.
198 .SS Publishing
199 .P
200 Upon publishing, npm will look in the \fBnode_modules\fP folder\.  If any of
201 the items there are not in the \fBbundledDependencies\fP array, then they will
202 not be included in the package tarball\.
203 .P
204 This allows a package maintainer to install all of their dependencies
205 (and dev dependencies) locally, but only re\-publish those items that
206 cannot be found elsewhere\.  See npm help 5 \fBpackage\.json\fP for more information\.
207 .SH SEE ALSO
208 .RS 0
209 .IP \(bu 2
210 npm help 7 faq
211 .IP \(bu 2
212 npm help 5 package\.json
213 .IP \(bu 2
214 npm help install
215 .IP \(bu 2
216 npm help pack
217 .IP \(bu 2
218 npm help cache
219 .IP \(bu 2
220 npm help config
221 .IP \(bu 2
222 npm help 5 npmrc
223 .IP \(bu 2
224 npm help 7 config
225 .IP \(bu 2
226 npm help publish
227
228 .RE
229