1---
2title: developers
3section: 7
4description: Developer Guide
5---
6
7### Description
8
9So, you've decided to use npm to develop (and maybe publish/deploy)
10your project.
11
12Fantastic!
13
14There are a few things that you need to do above the simple steps
15that your users will do to install your program.
16
17### About These Documents
18
19These are man pages.  If you install npm, you should be able to
20then do `man npm-thing` to get the documentation on a particular
21topic, or `npm help thing` to see the same information.
22
23### What is a Package
24
25A package is:
26
27* a) a folder containing a program described by a package.json file
28* b) a gzipped tarball containing (a)
29* c) a url that resolves to (b)
30* d) a `<name>@<version>` that is published on the registry with (c)
31* e) a `<name>@<tag>` that points to (d)
32* f) a `<name>` that has a "latest" tag satisfying (e)
33* g) a `git` url that, when cloned, results in (a).
34
35Even if you never publish your package, you can still get a lot of
36benefits of using npm if you just want to write a node program (a), and
37perhaps if you also want to be able to easily install it elsewhere
38after packing it up into a tarball (b).
39
40Git urls can be of the form:
41
42```bash
43git://github.com/user/project.git#commit-ish
44git+ssh://user@hostname:project.git#commit-ish
45git+http://user@hostname/project/blah.git#commit-ish
46git+https://user@hostname/project/blah.git#commit-ish
47```
48
49The `commit-ish` can be any tag, sha, or branch which can be supplied as
50an argument to `git checkout`.  The default is whatever the repository uses
51as its default branch.
52
53### The package.json File
54
55You need to have a `package.json` file in the root of your project to do
56much of anything with npm.  That is basically the whole interface.
57
58See [`package.json`](/configuring-npm/package-json) for details about what
59goes in that file.  At the very least, you need:
60
61* name: This should be a string that identifies your project.  Please do
62  not use the name to specify that it runs on node, or is in JavaScript.
63  You can use the "engines" field to explicitly state the versions of node
64  (or whatever else) that your program requires, and it's pretty well
65  assumed that it's JavaScript.
66
67  It does not necessarily need to match your github repository name.
68
69  So, `node-foo` and `bar-js` are bad names.  `foo` or `bar` are better.
70
71* version: A semver-compatible version.
72
73* engines: Specify the versions of node (or whatever else) that your
74  program runs on.  The node API changes a lot, and there may be bugs or
75  new functionality that you depend on.  Be explicit.
76
77* author: Take some credit.
78
79* scripts: If you have a special compilation or installation script, then
80  you should put it in the `scripts` object.  You should definitely have at
81  least a basic smoke-test command as the "scripts.test" field.  See
82  [scripts](/using-npm/scripts).
83
84* main: If you have a single module that serves as the entry point to your
85  program (like what the "foo" package gives you at require("foo")), then
86  you need to specify that in the "main" field.
87
88* directories: This is an object mapping names to folders.  The best ones
89  to include are "lib" and "doc", but if you use "man" to specify a folder
90  full of man pages, they'll get installed just like these ones.
91
92You can use `npm init` in the root of your package in order to get you
93started with a pretty basic package.json file.  See [`npm
94init`](/commands/npm-init) for more info.
95
96### Keeping files *out* of your Package
97
98Use a `.npmignore` file to keep stuff out of your package.  If there's no
99`.npmignore` file, but there *is* a `.gitignore` file, then npm will ignore
100the stuff matched by the `.gitignore` file.  If you *want* to include
101something that is excluded by your `.gitignore` file, you can create an
102empty `.npmignore` file to override it. Like `git`, `npm` looks for
103`.npmignore` and `.gitignore` files in all subdirectories of your package,
104not only the root directory.
105
106`.npmignore` files follow the [same pattern
107rules](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring)
108as `.gitignore` files:
109
110* Blank lines or lines starting with `#` are ignored.
111* Standard glob patterns work.
112* You can end patterns with a forward slash `/` to specify a directory.
113* You can negate a pattern by starting it with an exclamation point `!`.
114
115By default, the following paths and files are ignored, so there's no
116need to add them to `.npmignore` explicitly:
117
118* `.*.swp`
119* `._*`
120* `.DS_Store`
121* `.git`
122* `.gitignore`
123* `.hg`
124* `.npmignore`
125* `.npmrc`
126* `.lock-wscript`
127* `.svn`
128* `.wafpickle-*`
129* `config.gypi`
130* `CVS`
131* `npm-debug.log`
132
133Additionally, everything in `node_modules` is ignored, except for
134bundled dependencies. npm automatically handles this for you, so don't
135bother adding `node_modules` to `.npmignore`.
136
137The following paths and files are never ignored, so adding them to
138`.npmignore` is pointless:
139
140* `package.json`
141* `README` (and its variants)
142* `CHANGELOG` (and its variants)
143* `LICENSE` / `LICENCE`
144
145If, given the structure of your project, you find `.npmignore` to be a
146maintenance headache, you might instead try populating the `files`
147property of `package.json`, which is an array of file or directory names
148that should be included in your package. Sometimes manually picking
149which items to allow is easier to manage than building a block list.
150
151#### Testing whether your `.npmignore` or `files` config works
152
153If you want to double check that your package will include only the files
154you intend it to when published, you can run the `npm pack` command locally
155which will generate a tarball in the working directory, the same way it
156does for publishing.
157
158### Link Packages
159
160`npm link` is designed to install a development package and see the
161changes in real time without having to keep re-installing it.  (You do
162need to either re-link or `npm rebuild -g` to update compiled packages,
163of course.)
164
165More info at [`npm link`](/commands/npm-link).
166
167### Before Publishing: Make Sure Your Package Installs and Works
168
169**This is important.**
170
171If you can not install it locally, you'll have
172problems trying to publish it.  Or, worse yet, you'll be able to
173publish it, but you'll be publishing a broken or pointless package.
174So don't do that.
175
176In the root of your package, do this:
177
178```bash
179npm install . -g
180```
181
182That'll show you that it's working.  If you'd rather just create a symlink
183package that points to your working directory, then do this:
184
185```bash
186npm link
187```
188
189Use `npm ls -g` to see if it's there.
190
191To test a local install, go into some other folder, and then do:
192
193```bash
194cd ../some-other-folder
195npm install ../my-package
196```
197
198to install it locally into the node_modules folder in that other place.
199
200Then go into the node-repl, and try using require("my-thing") to
201bring in your module's main module.
202
203### Create a User Account
204
205Create a user with the adduser command.  It works like this:
206
207```bash
208npm adduser
209```
210
211and then follow the prompts.
212
213This is documented better in [npm adduser](/commands/npm-adduser).
214
215### Publish your Package
216
217This part's easy.  In the root of your folder, do this:
218
219```bash
220npm publish
221```
222
223You can give publish a url to a tarball, or a filename of a tarball,
224or a path to a folder.
225
226Note that pretty much **everything in that folder will be exposed**
227by default.  So, if you have secret stuff in there, use a
228`.npmignore` file to list out the globs to ignore, or publish
229from a fresh checkout.
230
231### Brag about it
232
233Send emails, write blogs, blab in IRC.
234
235Tell the world how easy it is to install your program!
236
237### See also
238
239* [npm](/commands/npm)
240* [npm init](/commands/npm-init)
241* [package.json](/configuring-npm/package-json)
242* [npm scripts](/using-npm/scripts)
243* [npm publish](/commands/npm-publish)
244* [npm adduser](/commands/npm-adduser)
245* [npm registry](/using-npm/registry)
246