bf3c7f227137ada733c755e0c29a9dced07bd645
[platform/upstream/nodejs.git] / deps / npm / man / man7 / npm-developers.7
1 .\" Generated with Ronnjs 0.3.8
2 .\" http://github.com/kapouer/ronnjs/
3 .
4 .TH "NPM\-DEVELOPERS" "7" "November 2013" "" ""
5 .
6 .SH "NAME"
7 \fBnpm-developers\fR \-\- Developer Guide
8 .
9 .SH "DESCRIPTION"
10 So, you\'ve decided to use npm to develop (and maybe publish/deploy)
11 your project\.
12 .
13 .P
14 Fantastic!
15 .
16 .P
17 There are a few things that you need to do above the simple steps
18 that your users will do to install your program\.
19 .
20 .SH "About These Documents"
21 These are man pages\.  If you install npm, you should be able to
22 then do \fBman npm\-thing\fR to get the documentation on a particular
23 topic, or \fBnpm help thing\fR to see the same information\.
24 .
25 .SH "What is a "
26 A package is:
27 .
28 .IP "\(bu" 4
29 a) a folder containing a program described by a package\.json file
30 .
31 .IP "\(bu" 4
32 b) a gzipped tarball containing (a)
33 .
34 .IP "\(bu" 4
35 c) a url that resolves to (b)
36 .
37 .IP "\(bu" 4
38 d) a \fB<name>@<version>\fR that is published on the registry with (c)
39 .
40 .IP "\(bu" 4
41 e) a \fB<name>@<tag>\fR that points to (d)
42 .
43 .IP "\(bu" 4
44 f) a \fB<name>\fR that has a "latest" tag satisfying (e)
45 .
46 .IP "\(bu" 4
47 g) a \fBgit\fR url that, when cloned, results in (a)\.
48 .
49 .IP "" 0
50 .
51 .P
52 Even if you never publish your package, you can still get a lot of
53 benefits of using npm if you just want to write a node program (a), and
54 perhaps if you also want to be able to easily install it elsewhere
55 after packing it up into a tarball (b)\.
56 .
57 .P
58 Git urls can be of the form:
59 .
60 .IP "" 4
61 .
62 .nf
63 git://github\.com/user/project\.git#commit\-ish
64 git+ssh://user@hostname:project\.git#commit\-ish
65 git+http://user@hostname/project/blah\.git#commit\-ish
66 git+https://user@hostname/project/blah\.git#commit\-ish
67 .
68 .fi
69 .
70 .IP "" 0
71 .
72 .P
73 The \fBcommit\-ish\fR can be any tag, sha, or branch which can be supplied as
74 an argument to \fBgit checkout\fR\|\.  The default is \fBmaster\fR\|\.
75 .
76 .SH "The package\.json File"
77 You need to have a \fBpackage\.json\fR file in the root of your project to do
78 much of anything with npm\.  That is basically the whole interface\.
79 .
80 .P
81 npm help  See \fBpackage\.json\fR for details about what goes in that file\.  At the very
82 least, you need:
83 .
84 .IP "\(bu" 4
85 name:
86 This should be a string that identifies your project\.  Please do not
87 use the name to specify that it runs on node, or is in JavaScript\.
88 You can use the "engines" field to explicitly state the versions of
89 node (or whatever else) that your program requires, and it\'s pretty
90 well assumed that it\'s javascript\.
91 .
92 .IP
93 It does not necessarily need to match your github repository name\.
94 .
95 .IP
96 So, \fBnode\-foo\fR and \fBbar\-js\fR are bad names\.  \fBfoo\fR or \fBbar\fR are better\.
97 .
98 .IP "\(bu" 4
99 version:
100 A semver\-compatible version\.
101 .
102 .IP "\(bu" 4
103 engines:
104 Specify the versions of node (or whatever else) that your program
105 runs on\.  The node API changes a lot, and there may be bugs or new
106 functionality that you depend on\.  Be explicit\.
107 .
108 .IP "\(bu" 4
109 author:
110 Take some credit\.
111 .
112 .IP "\(bu" 4
113 scripts:
114 If you have a special compilation or installation script, then you
115 should put it in the \fBscripts\fR hash\.  You should definitely have at
116 least a basic smoke\-test command as the "scripts\.test" field\.
117 npm help  See npm\-scripts\.
118 .
119 .IP "\(bu" 4
120 main:
121 If you have a single module that serves as the entry point to your
122 program (like what the "foo" package gives you at require("foo")),
123 then you need to specify that in the "main" field\.
124 .
125 .IP "\(bu" 4
126 directories:
127 This is a hash of folders\.  The best ones to include are "lib" and
128 "doc", but if you specify a folder full of man pages in "man", then
129 they\'ll get installed just like these ones\.
130 .
131 .IP "" 0
132 .
133 .P
134 You can use \fBnpm init\fR in the root of your package in order to get you
135 npm help started with a pretty basic package\.json file\.  See \fBnpm\-init\fR for
136 more info\.
137 .
138 .SH "Keeping files "
139 Use a \fB\|\.npmignore\fR file to keep stuff out of your package\.  If there\'s
140 no \fB\|\.npmignore\fR file, but there \fIis\fR a \fB\|\.gitignore\fR file, then npm will
141 ignore the stuff matched by the \fB\|\.gitignore\fR file\.  If you \fIwant\fR to
142 include something that is excluded by your \fB\|\.gitignore\fR file, you can
143 create an empty \fB\|\.npmignore\fR file to override it\.
144 .
145 .P
146 By default, the following paths and files are ignored, so there\'s no
147 need to add them to \fB\|\.npmignore\fR explicitly:
148 .
149 .IP "\(bu" 4
150 \fB\|\.*\.swp\fR
151 .
152 .IP "\(bu" 4
153 \fB\|\._*\fR
154 .
155 .IP "\(bu" 4
156 \fB\|\.DS_Store\fR
157 .
158 .IP "\(bu" 4
159 \fB\|\.git\fR
160 .
161 .IP "\(bu" 4
162 \fB\|\.hg\fR
163 .
164 .IP "\(bu" 4
165 \fB\|\.lock\-wscript\fR
166 .
167 .IP "\(bu" 4
168 \fB\|\.svn\fR
169 .
170 .IP "\(bu" 4
171 \fB\|\.wafpickle\-*\fR
172 .
173 .IP "\(bu" 4
174 \fBCVS\fR
175 .
176 .IP "\(bu" 4
177 \fBnpm\-debug\.log\fR
178 .
179 .IP "" 0
180 .
181 .P
182 Additionally, everything in \fBnode_modules\fR is ignored, except for
183 bundled dependencies\. npm automatically handles this for you, so don\'t
184 bother adding \fBnode_modules\fR to \fB\|\.npmignore\fR\|\.
185 .
186 .P
187 The following paths and files are never ignored, so adding them to \fB\|\.npmignore\fR is pointless:
188 .
189 .IP "\(bu" 4
190 \fBpackage\.json\fR
191 .
192 .IP "\(bu" 4
193 \fBREADME\.*\fR
194 .
195 .IP "" 0
196 .
197 .SH "Link Packages"
198 \fBnpm link\fR is designed to install a development package and see the
199 changes in real time without having to keep re\-installing it\.  (You do
200 need to either re\-link or \fBnpm rebuild \-g\fR to update compiled packages,
201 of course\.)
202 .
203 .P
204 npm help More info at \fBnpm\-link\fR\|\.
205 .
206 .SH "Before Publishing: Make Sure Your Package Installs and Works"
207 \fBThis is important\.\fR
208 .
209 .P
210 If you can not install it locally, you\'ll have
211 problems trying to publish it\.  Or, worse yet, you\'ll be able to
212 publish it, but you\'ll be publishing a broken or pointless package\.
213 So don\'t do that\.
214 .
215 .P
216 In the root of your package, do this:
217 .
218 .IP "" 4
219 .
220 .nf
221 npm install \. \-g
222 .
223 .fi
224 .
225 .IP "" 0
226 .
227 .P
228 That\'ll show you that it\'s working\.  If you\'d rather just create a symlink
229 package that points to your working directory, then do this:
230 .
231 .IP "" 4
232 .
233 .nf
234 npm link
235 .
236 .fi
237 .
238 .IP "" 0
239 .
240 .P
241 Use \fBnpm ls \-g\fR to see if it\'s there\.
242 .
243 .P
244 To test a local install, go into some other folder, and then do:
245 .
246 .IP "" 4
247 .
248 .nf
249 cd \.\./some\-other\-folder
250 npm install \.\./my\-package
251 .
252 .fi
253 .
254 .IP "" 0
255 .
256 .P
257 to install it locally into the node_modules folder in that other place\.
258 .
259 .P
260 Then go into the node\-repl, and try using require("my\-thing") to
261 bring in your module\'s main module\.
262 .
263 .SH "Create a User Account"
264 Create a user with the adduser command\.  It works like this:
265 .
266 .IP "" 4
267 .
268 .nf
269 npm adduser
270 .
271 .fi
272 .
273 .IP "" 0
274 .
275 .P
276 and then follow the prompts\.
277 .
278 .P
279 npm help This is documented better in npm\-adduser\.
280 .
281 .SH "Publish your package"
282 This part\'s easy\.  IN the root of your folder, do this:
283 .
284 .IP "" 4
285 .
286 .nf
287 npm publish
288 .
289 .fi
290 .
291 .IP "" 0
292 .
293 .P
294 You can give publish a url to a tarball, or a filename of a tarball,
295 or a path to a folder\.
296 .
297 .P
298 Note that pretty much \fBeverything in that folder will be exposed\fR
299 by default\.  So, if you have secret stuff in there, use a \fB\|\.npmignore\fR file to list out the globs to ignore, or publish
300 from a fresh checkout\.
301 .
302 .SH "Brag about it"
303 Send emails, write blogs, blab in IRC\.
304 .
305 .P
306 Tell the world how easy it is to install your program!
307 .
308 .SH "SEE ALSO"
309 .
310 .IP "\(bu" 4
311 npm help  faq
312 .
313 .IP "\(bu" 4
314 npm help npm
315 .
316 .IP "\(bu" 4
317 npm help init
318 .
319 .IP "\(bu" 4
320 npm help  package\.json
321 .
322 .IP "\(bu" 4
323 npm help  scripts
324 .
325 .IP "\(bu" 4
326 npm help publish
327 .
328 .IP "\(bu" 4
329 npm help adduser
330 .
331 .IP "\(bu" 4
332 npm help  registry
333 .
334 .IP "" 0
335