1 .TH "NPM\-DEVELOPERS" "7" "March 2015" "" ""
3 \fBnpm-developers\fR \- Developer Guide
6 So, you've decided to use npm to develop (and maybe publish/deploy)
11 There are a few things that you need to do above the simple steps
12 that your users will do to install your program\.
13 .SH About These Documents
15 These are man pages\. If you install npm, you should be able to
16 then do \fBman npm\-thing\fR to get the documentation on a particular
17 topic, or \fBnpm help thing\fR to see the same information\.
18 .SH What is a \fBpackage\fR
23 a) a folder containing a program described by a package\.json file
25 b) a gzipped tarball containing (a)
27 c) a url that resolves to (b)
29 d) a \fB<name>@<version>\fR that is published on the registry with (c)
31 e) a \fB<name>@<tag>\fR that points to (d)
33 f) a \fB<name>\fR that has a "latest" tag satisfying (e)
35 g) a \fBgit\fR url that, when cloned, results in (a)\.
39 Even if you never publish your package, you can still get a lot of
40 benefits of using npm if you just want to write a node program (a), and
41 perhaps if you also want to be able to easily install it elsewhere
42 after packing it up into a tarball (b)\.
44 Git urls can be of the form:
48 git://github\.com/user/project\.git#commit\-ish
49 git+ssh://user@hostname:project\.git#commit\-ish
50 git+http://user@hostname/project/blah\.git#commit\-ish
51 git+https://user@hostname/project/blah\.git#commit\-ish
55 The \fBcommit\-ish\fR can be any tag, sha, or branch which can be supplied as
56 an argument to \fBgit checkout\fR\|\. The default is \fBmaster\fR\|\.
57 .SH The package\.json File
59 You need to have a \fBpackage\.json\fR file in the root of your project to do
60 much of anything with npm\. That is basically the whole interface\.
62 See npm help 5 \fBpackage\.json\fR for details about what goes in that file\. At the very
67 This should be a string that identifies your project\. Please do not
68 use the name to specify that it runs on node, or is in JavaScript\.
69 You can use the "engines" field to explicitly state the versions of
70 node (or whatever else) that your program requires, and it's pretty
71 well assumed that it's javascript\.
72 It does not necessarily need to match your github repository name\.
73 So, \fBnode\-foo\fR and \fBbar\-js\fR are bad names\. \fBfoo\fR or \fBbar\fR are better\.
76 A semver\-compatible version\.
79 Specify the versions of node (or whatever else) that your program
80 runs on\. The node API changes a lot, and there may be bugs or new
81 functionality that you depend on\. Be explicit\.
87 If you have a special compilation or installation script, then you
88 should put it in the \fBscripts\fR object\. You should definitely have at
89 least a basic smoke\-test command as the "scripts\.test" field\.
90 See npm help 7 scripts\.
93 If you have a single module that serves as the entry point to your
94 program (like what the "foo" package gives you at require("foo")),
95 then you need to specify that in the "main" field\.
98 This is an object mapping names to folders\. The best ones to include are
99 "lib" and "doc", but if you use "man" to specify a folder full of man pages,
100 they'll get installed just like these ones\.
104 You can use \fBnpm init\fR in the root of your package in order to get you
105 started with a pretty basic package\.json file\. See npm help \fBnpm\-init\fR for
107 .SH Keeping files \fIout\fR of your package
109 Use a \fB\|\.npmignore\fR file to keep stuff out of your package\. If there's
110 no \fB\|\.npmignore\fR file, but there \fIis\fR a \fB\|\.gitignore\fR file, then npm will
111 ignore the stuff matched by the \fB\|\.gitignore\fR file\. If you \fIwant\fR to
112 include something that is excluded by your \fB\|\.gitignore\fR file, you can
113 create an empty \fB\|\.npmignore\fR file to override it\.
115 \fB\|\.npmignore\fR files follow the same pattern rules \fIhttp://git\-scm\.com/book/en/v2/Git\-Basics\-Recording\-Changes\-to\-the\-Repository#Ignoring\-Files\fR
116 as \fB\|\.gitignore\fR files:
119 Blank lines or lines starting with \fB#\fR are ignored\.
121 Standard glob patterns work\.
123 You can end patterns with a forward slash \fB/\fR to specify a directory\.
125 You can negate a pattern by starting it with an exclamation point \fB!\fR\|\.
129 By default, the following paths and files are ignored, so there's no
130 need to add them to \fB\|\.npmignore\fR explicitly:
143 \fB\|\.lock\-wscript\fR
147 \fB\|\.wafpickle\-*\fR
151 \fBnpm\-debug\.log\fR
155 Additionally, everything in \fBnode_modules\fR is ignored, except for
156 bundled dependencies\. npm automatically handles this for you, so don't
157 bother adding \fBnode_modules\fR to \fB\|\.npmignore\fR\|\.
159 The following paths and files are never ignored, so adding them to
160 \fB\|\.npmignore\fR is pointless:
170 \fBnpm link\fR is designed to install a development package and see the
171 changes in real time without having to keep re\-installing it\. (You do
172 need to either re\-link or \fBnpm rebuild \-g\fR to update compiled packages,
175 More info at npm help \fBnpm\-link\fR\|\.
176 .SH Before Publishing: Make Sure Your Package Installs and Works
178 \fBThis is important\.\fR
180 If you can not install it locally, you'll have
181 problems trying to publish it\. Or, worse yet, you'll be able to
182 publish it, but you'll be publishing a broken or pointless package\.
185 In the root of your package, do this:
193 That'll show you that it's working\. If you'd rather just create a symlink
194 package that points to your working directory, then do this:
202 Use \fBnpm ls \-g\fR to see if it's there\.
204 To test a local install, go into some other folder, and then do:
208 cd \.\./some\-other\-folder
209 npm install \.\./my\-package
213 to install it locally into the node_modules folder in that other place\.
215 Then go into the node\-repl, and try using require("my\-thing") to
216 bring in your module's main module\.
217 .SH Create a User Account
219 Create a user with the adduser command\. It works like this:
227 and then follow the prompts\.
229 This is documented better in npm help adduser\.
230 .SH Publish your package
232 This part's easy\. IN the root of your folder, do this:
240 You can give publish a url to a tarball, or a filename of a tarball,
241 or a path to a folder\.
243 Note that pretty much \fBeverything in that folder will be exposed\fR
244 by default\. So, if you have secret stuff in there, use a
245 \fB\|\.npmignore\fR file to list out the globs to ignore, or publish
246 from a fresh checkout\.
249 Send emails, write blogs, blab in IRC\.
251 Tell the world how easy it is to install your program!
261 npm help 5 package\.json