3 <title>package.json</title>
4 <meta http-equiv="content-type" value="text/html;utf-8">
5 <link rel="stylesheet" type="text/css" href="../../static/style.css">
9 <h1><a href="../files/package.json.html">package.json</a></h1> <p>Specifics of npm's package.json handling</p>
11 <h2 id="DESCRIPTION">DESCRIPTION</h2>
13 <p>This document is all you need to know about what's required in your package.json
14 file. It must be actual JSON, not just a JavaScript object literal.</p>
16 <p>A lot of the behavior described in this document is affected by the config
17 settings described in <code><a href="../misc/npm-config.html">npm-config(7)</a></code>.</p>
19 <h2 id="DEFAULT-VALUES">DEFAULT VALUES</h2>
21 <p>npm will default some values based on package contents.</p>
23 <ul><li><p><code>"scripts": {"start": "node server.js"}</code></p><p>If there is a <code>server.js</code> file in the root of your package, then npm
24 will default the <code>start</code> command to <code>node server.js</code>.</p></li><li><p><code>"scripts":{"preinstall": "node-waf clean || true; node-waf configure build"}</code></p><p>If there is a <code>wscript</code> file in the root of your package, npm will
25 default the <code>preinstall</code> command to compile using node-waf.</p></li><li><p><code>"scripts":{"preinstall": "node-gyp rebuild"}</code></p><p>If there is a <code>binding.gyp</code> file in the root of your package, npm will
26 default the <code>preinstall</code> command to compile using node-gyp.</p></li><li><p><code>"contributors": [...]</code></p><p>If there is an <code>AUTHORS</code> file in the root of your package, npm will
27 treat each line as a <code>Name <email> (url)</code> format, where email and url
28 are optional. Lines which start with a <code>#</code> or are blank, will be
29 ignored.</p></li></ul>
31 <h2 id="name">name</h2>
33 <p>The <em>most</em> important things in your package.json are the name and version fields.
34 Those are actually required, and your package won't install without
35 them. The name and version together form an identifier that is assumed
36 to be completely unique. Changes to the package should come along with
37 changes to the version.</p>
39 <p>The name is what your thing is called. Some tips:</p>
41 <ul><li>Don't put "js" or "node" in the name. It's assumed that it's js, since you're
42 writing a package.json file, and you can specify the engine using the "engines"
43 field. (See below.)</li><li>The name ends up being part of a URL, an argument on the command line, and a
44 folder name. Any name with non-url-safe characters will be rejected.
45 Also, it can't start with a dot or an underscore.</li><li>The name will probably be passed as an argument to require(), so it should
46 be something short, but also reasonably descriptive.</li><li>You may want to check the npm registry to see if there's something by that name
47 already, before you get too attached to it. http://registry.npmjs.org/</li></ul>
49 <h2 id="version">version</h2>
51 <p>The <em>most</em> important things in your package.json are the name and version fields.
52 Those are actually required, and your package won't install without
53 them. The name and version together form an identifier that is assumed
54 to be completely unique. Changes to the package should come along with
55 changes to the version.</p>
57 <p>Version must be parseable by
58 <a href="https://github.com/isaacs/node-semver">node-semver</a>, which is bundled
59 with npm as a dependency. (<code>npm install semver</code> to use it yourself.)</p>
61 <p>More on version numbers and ranges at <a href="../misc/semver.html">semver(7)</a>.</p>
63 <h2 id="description">description</h2>
65 <p>Put a description in it. It's a string. This helps people discover your
66 package, as it's listed in <code>npm search</code>.</p>
68 <h2 id="keywords">keywords</h2>
70 <p>Put keywords in it. It's an array of strings. This helps people
71 discover your package as it's listed in <code>npm search</code>.</p>
73 <h2 id="homepage">homepage</h2>
75 <p>The url to the project homepage.</p>
77 <p><strong>NOTE</strong>: This is <em>not</em> the same as "url". If you put a "url" field,
78 then the registry will think it's a redirection to your package that has
79 been published somewhere else, and spit at you.</p>
81 <p>Literally. Spit. I'm so not kidding.</p>
83 <h2 id="bugs">bugs</h2>
85 <p>The url to your project's issue tracker and / or the email address to which
86 issues should be reported. These are helpful for people who encounter issues
87 with your package.</p>
89 <p>It should look like this:</p>
91 <pre><code>{ "url" : "http://github.com/owner/project/issues"
92 , "email" : "project@hostname.com"
95 <p>You can specify either one or both values. If you want to provide only a url,
96 you can specify the value for "bugs" as a simple string instead of an object.</p>
98 <p>If a url is provided, it will be used by the <code>npm bugs</code> command.</p>
100 <h2 id="license">license</h2>
102 <p>You should specify a license for your package so that people know how they are
103 permitted to use it, and any restrictions you're placing on it.</p>
105 <p>The simplest way, assuming you're using a common license such as BSD-3-Clause
106 or MIT, is to just specify the standard SPDX ID of the license you're using,
109 <pre><code>{ "license" : "BSD-3-Clause" }</code></pre>
111 <p>You can check <a href="https://spdx.org/licenses/">the full list of SPDX license IDs</a>.
112 Ideally you should pick one that is
113 <a href="http://opensource.org/licenses/alphabetical">OSI</a> approved.</p>
115 <p>If you have more complex licensing terms, or you want to provide more detail
116 in your package.json file, you can use the more verbose plural form, like this:</p>
118 <pre><code>"licenses" : [
119 { "type" : "MyLicense"
120 , "url" : "http://github.com/owner/project/path/to/license"
124 <p>It's also a good idea to include a license file at the top level in your package.</p>
126 <h2 id="people-fields-author-contributors">people fields: author, contributors</h2>
128 <p>The "author" is one person. "contributors" is an array of people. A "person"
129 is an object with a "name" field and optionally "url" and "email", like this:</p>
131 <pre><code>{ "name" : "Barney Rubble"
132 , "email" : "b@rubble.com"
133 , "url" : "http://barnyrubble.tumblr.com/"
136 <p>Or you can shorten that all into a single string, and npm will parse it for you:</p>
138 <pre><code>"Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)</code></pre>
140 <p>Both email and url are optional either way.</p>
142 <p>npm also sets a top-level "maintainers" field with your npm user info.</p>
144 <h2 id="files">files</h2>
146 <p>The "files" field is an array of files to include in your project. If
147 you name a folder in the array, then it will also include the files
148 inside that folder. (Unless they would be ignored by another rule.)</p>
150 <p>You can also provide a ".npmignore" file in the root of your package,
151 which will keep files from being included, even if they would be picked
152 up by the files array. The ".npmignore" file works just like a
153 ".gitignore".</p>
155 <h2 id="main">main</h2>
157 <p>The main field is a module ID that is the primary entry point to your program.
158 That is, if your package is named <code>foo</code>, and a user installs it, and then does
159 <code>require("foo")</code>, then your main module's exports object will be returned.</p>
161 <p>This should be a module ID relative to the root of your package folder.</p>
163 <p>For most modules, it makes the most sense to have a main script and often not
166 <h2 id="bin">bin</h2>
168 <p>A lot of packages have one or more executable files that they'd like to
169 install into the PATH. npm makes this pretty easy (in fact, it uses this
170 feature to install the "npm" executable.)</p>
172 <p>To use this, supply a <code>bin</code> field in your package.json which is a map of
173 command name to local file name. On install, npm will symlink that file into
174 <code>prefix/bin</code> for global installs, or <code>./node_modules/.bin/</code> for local
177 <p>For example, npm has this:</p>
179 <pre><code>{ "bin" : { "npm" : "./cli.js" } }</code></pre>
181 <p>So, when you install npm, it'll create a symlink from the <code>cli.js</code> script to
182 <code>/usr/local/bin/npm</code>.</p>
184 <p>If you have a single executable, and its name should be the name
185 of the package, then you can just supply it as a string. For example:</p>
187 <pre><code>{ "name": "my-program"
188 , "version": "1.2.5"
189 , "bin": "./path/to/program" }</code></pre>
191 <p>would be the same as this:</p>
193 <pre><code>{ "name": "my-program"
194 , "version": "1.2.5"
195 , "bin" : { "my-program" : "./path/to/program" } }</code></pre>
197 <h2 id="man">man</h2>
199 <p>Specify either a single file or an array of filenames to put in place for the
200 <code>man</code> program to find.</p>
202 <p>If only a single file is provided, then it's installed such that it is the
203 result from <code>man <pkgname></code>, regardless of its actual filename. For example:</p>
205 <pre><code>{ "name" : "foo"
206 , "version" : "1.2.3"
207 , "description" : "A packaged foo fooer for fooing foos"
208 , "main" : "foo.js"
209 , "man" : "./man/doc.1"
212 <p>would link the <code>./man/doc.1</code> file in such that it is the target for <code>man foo</code></p>
214 <p>If the filename doesn't start with the package name, then it's prefixed.
217 <pre><code>{ "name" : "foo"
218 , "version" : "1.2.3"
219 , "description" : "A packaged foo fooer for fooing foos"
220 , "main" : "foo.js"
221 , "man" : [ "./man/foo.1", "./man/bar.1" ]
224 <p>will create files to do <code>man foo</code> and <code>man foo-bar</code>.</p>
226 <p>Man files must end with a number, and optionally a <code>.gz</code> suffix if they are
227 compressed. The number dictates which man section the file is installed into.</p>
229 <pre><code>{ "name" : "foo"
230 , "version" : "1.2.3"
231 , "description" : "A packaged foo fooer for fooing foos"
232 , "main" : "foo.js"
233 , "man" : [ "./man/foo.1", "./man/foo.2" ]
236 <p>will create entries for <code>man foo</code> and <code>man 2 foo</code></p>
238 <h2 id="directories">directories</h2>
240 <p>The CommonJS <a href="http://wiki.commonjs.org/wiki/Packages/1.0">Packages</a> spec details a
241 few ways that you can indicate the structure of your package using a <code>directories</code>
242 hash. If you look at <a href="http://registry.npmjs.org/npm/latest">npm's package.json</a>,
243 you'll see that it has directories for doc, lib, and man.</p>
245 <p>In the future, this information may be used in other creative ways.</p>
247 <h3 id="directories-lib">directories.lib</h3>
249 <p>Tell people where the bulk of your library is. Nothing special is done
250 with the lib folder in any way, but it's useful meta info.</p>
252 <h3 id="directories-bin">directories.bin</h3>
254 <p>If you specify a "bin" directory, then all the files in that folder will
255 be used as the "bin" hash.</p>
257 <p>If you have a "bin" hash already, then this has no effect.</p>
259 <h3 id="directories-man">directories.man</h3>
261 <p>A folder that is full of man pages. Sugar to generate a "man" array by
262 walking the folder.</p>
264 <h3 id="directories-doc">directories.doc</h3>
266 <p>Put markdown files in here. Eventually, these will be displayed nicely,
269 <h3 id="directories-example">directories.example</h3>
271 <p>Put example scripts in here. Someday, it might be exposed in some clever way.</p>
273 <h2 id="repository">repository</h2>
275 <p>Specify the place where your code lives. This is helpful for people who
276 want to contribute. If the git repo is on github, then the <code>npm docs</code>
277 command will be able to find you.</p>
279 <p>Do it like this:</p>
281 <pre><code>"repository" :
282 { "type" : "git"
283 , "url" : "http://github.com/isaacs/npm.git"
286 "repository" :
287 { "type" : "svn"
288 , "url" : "http://v8.googlecode.com/svn/trunk/"
291 <p>The URL should be a publicly available (perhaps read-only) url that can be handed
292 directly to a VCS program without any modification. It should not be a url to an
293 html project page that you put in your browser. It's for computers.</p>
295 <h2 id="scripts">scripts</h2>
297 <p>The "scripts" member is an object hash of script commands that are run
298 at various times in the lifecycle of your package. The key is the lifecycle
299 event, and the value is the command to run at that point.</p>
301 <p>See <code><a href="../misc/npm-scripts.html">npm-scripts(7)</a></code> to find out more about writing package scripts.</p>
303 <h2 id="config">config</h2>
305 <p>A "config" hash can be used to set configuration
306 parameters used in package scripts that persist across upgrades. For
307 instance, if a package had the following:</p>
309 <pre><code>{ "name" : "foo"
310 , "config" : { "port" : "8080" } }</code></pre>
312 <p>and then had a "start" command that then referenced the
313 <code>npm_package_config_port</code> environment variable, then the user could
314 override that by doing <code>npm config set foo:port 8001</code>.</p>
316 <p>See <code><a href="../misc/npm-config.html">npm-config(7)</a></code> and <code><a href="../misc/npm-scripts.html">npm-scripts(7)</a></code> for more on package
319 <h2 id="dependencies">dependencies</h2>
321 <p>Dependencies are specified with a simple hash of package name to
322 version range. The version range is a string which has one or more
323 space-separated descriptors. Dependencies can also be identified with
324 a tarball or git URL.</p>
326 <p><strong>Please do not put test harnesses or transpilers in your
327 <code>dependencies</code> hash.</strong> See <code>devDependencies</code>, below.</p>
329 <p>See <a href="../misc/semver.html">semver(7)</a> for more details about specifying version ranges.</p>
331 <ul><li><code>version</code> Must match <code>version</code> exactly</li><li><code>>version</code> Must be greater than <code>version</code></li><li><code>>=version</code> etc</li><li><code><version</code></li><li><code><=version</code></li><li><code>~version</code> "Approximately equivalent to version" See <a href="../misc/semver.html">semver(7)</a></li><li><code>1.2.x</code> 1.2.0, 1.2.1, etc., but not 1.3.0</li><li><code>http://...</code> See 'URLs as Dependencies' below</li><li><code>*</code> Matches any version</li><li><code>""</code> (just an empty string) Same as <code>*</code></li><li><code>version1 - version2</code> Same as <code>>=version1 <=version2</code>.</li><li><code>range1 || range2</code> Passes if either range1 or range2 are satisfied.</li><li><code>git...</code> See 'Git URLs as Dependencies' below</li><li><code>user/repo</code> See 'GitHub URLs' below</li></ul>
333 <p>For example, these are all valid:</p>
335 <pre><code>{ "dependencies" :
336 { "foo" : "1.0.0 - 2.9999.9999"
337 , "bar" : ">=1.0.2 <2.1.2"
338 , "baz" : ">1.0.2 <=2.3.4"
339 , "boo" : "2.0.1"
340 , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
341 , "asd" : "http://asdf.com/asdf.tar.gz"
342 , "til" : "~1.2"
343 , "elf" : "~1.2.3"
344 , "two" : "2.x"
345 , "thr" : "3.3.x"
349 <h3 id="URLs-as-Dependencies">URLs as Dependencies</h3>
351 <p>You may specify a tarball URL in place of a version range.</p>
353 <p>This tarball will be downloaded and installed locally to your package at
356 <h3 id="Git-URLs-as-Dependencies">Git URLs as Dependencies</h3>
358 <p>Git urls can be of the form:</p>
360 <pre><code>git://github.com/user/project.git#commit-ish
361 git+ssh://user@hostname:project.git#commit-ish
362 git+ssh://user@hostname/project.git#commit-ish
363 git+http://user@hostname/project/blah.git#commit-ish
364 git+https://user@hostname/project/blah.git#commit-ish</code></pre>
366 <p>The <code>commit-ish</code> can be any tag, sha, or branch which can be supplied as
367 an argument to <code>git checkout</code>. The default is <code>master</code>.</p>
369 <h2 id="GitHub-URLs">GitHub URLs</h2>
371 <p>As of version 1.1.65, you can refer to GitHub urls as just "foo": "user/foo-project". For example:</p>
375 "name": "foo",
376 "version": "0.0.0",
377 "dependencies": {
378 "express": "visionmedia/express"
383 <h2 id="devDependencies">devDependencies</h2>
385 <p>If someone is planning on downloading and using your module in their
386 program, then they probably don't want or need to download and build
387 the external test or documentation framework that you use.</p>
389 <p>In this case, it's best to list these additional items in a
390 <code>devDependencies</code> hash.</p>
392 <p>These things will be installed when doing <code>npm link</code> or <code>npm install</code>
393 from the root of a package, and can be managed like any other npm
394 configuration param. See <code><a href="../misc/npm-config.html">npm-config(7)</a></code> for more on the topic.</p>
396 <p>For build steps that are not platform-specific, such as compiling
397 CoffeeScript or other languages to JavaScript, use the <code>prepublish</code>
398 script to do this, and make the required package a devDependency.</p>
403 { "name": "ethopia-waza",
404 "description": "a delightfully fruity coffee varietal",
405 "version": "1.2.3",
406 "devDependencies": {
407 "coffee-script": "~1.6.3"
409 "scripts": {
410 "prepublish": "coffee -o lib/ -c src/waza.coffee"
412 "main": "lib/waza.js"
416 <p>The <code>prepublish</code> script will be run before publishing, so that users
417 can consume the functionality without requiring them to compile it
418 themselves. In dev mode (ie, locally running <code>npm install</code>), it'll
419 run this script as well, so that you can test it easily.</p>
421 <h2 id="bundledDependencies">bundledDependencies</h2>
423 <p>Array of package names that will be bundled when publishing the package.</p>
425 <p>If this is spelled <code>"bundleDependencies"</code>, then that is also honorable.</p>
427 <h2 id="optionalDependencies">optionalDependencies</h2>
429 <p>If a dependency can be used, but you would like npm to proceed if it
430 cannot be found or fails to install, then you may put it in the
431 <code>optionalDependencies</code> hash. This is a map of package name to version
432 or url, just like the <code>dependencies</code> hash. The difference is that
433 failure is tolerated.</p>
435 <p>It is still your program's responsibility to handle the lack of the
436 dependency. For example, something like this:</p>
439 var foo = require('foo')
440 var fooVersion = require('foo/package.json').version
444 if ( notGoodFooVersion(fooVersion) ) {
448 // .. then later in your program ..
454 <p>Entries in <code>optionalDependencies</code> will override entries of the same name in
455 <code>dependencies</code>, so it's usually best to only put in one place.</p>
457 <h2 id="engines">engines</h2>
459 <p>You can specify the version of node that your stuff works on:</p>
461 <pre><code>{ "engines" : { "node" : ">=0.10.3 <0.12" } }</code></pre>
463 <p>And, like with dependencies, if you don't specify the version (or if you
464 specify "*" as the version), then any version of node will do.</p>
466 <p>If you specify an "engines" field, then npm will require that "node" be
467 somewhere on that list. If "engines" is omitted, then npm will just assume
468 that it works on node.</p>
470 <p>You can also use the "engines" field to specify which versions of npm
471 are capable of properly installing your program. For example:</p>
473 <pre><code>{ "engines" : { "npm" : "~1.0.20" } }</code></pre>
475 <p>Note that, unless the user has set the <code>engine-strict</code> config flag, this
476 field is advisory only.</p>
478 <h2 id="engineStrict">engineStrict</h2>
480 <p>If you are sure that your module will <em>definitely not</em> run properly on
481 versions of Node/npm other than those specified in the <code>engines</code> hash,
482 then you can set <code>"engineStrict": true</code> in your package.json file.
483 This will override the user's <code>engine-strict</code> config setting.</p>
485 <p>Please do not do this unless you are really very very sure. If your
486 engines hash is something overly restrictive, you can quite easily and
487 inadvertently lock yourself into obscurity and prevent your users from
488 updating to new versions of Node. Consider this choice carefully. If
489 people abuse it, it will be removed in a future version of npm.</p>
493 <p>You can specify which operating systems your
494 module will run on:</p>
496 <pre><code>"os" : [ "darwin", "linux" ]</code></pre>
498 <p>You can also blacklist instead of whitelist operating systems,
499 just prepend the blacklisted os with a '!':</p>
501 <pre><code>"os" : [ "!win32" ]</code></pre>
503 <p>The host operating system is determined by <code>process.platform</code></p>
505 <p>It is allowed to both blacklist, and whitelist, although there isn't any
506 good reason to do this.</p>
508 <h2 id="cpu">cpu</h2>
510 <p>If your code only runs on certain cpu architectures,
511 you can specify which ones.</p>
513 <pre><code>"cpu" : [ "x64", "ia32" ]</code></pre>
515 <p>Like the <code>os</code> option, you can also blacklist architectures:</p>
517 <pre><code>"cpu" : [ "!arm", "!mips" ]</code></pre>
519 <p>The host architecture is determined by <code>process.arch</code></p>
521 <h2 id="preferGlobal">preferGlobal</h2>
523 <p>If your package is primarily a command-line application that should be
524 installed globally, then set this value to <code>true</code> to provide a warning
525 if it is installed locally.</p>
527 <p>It doesn't actually prevent users from installing it locally, but it
528 does help prevent some confusion if it doesn't work as expected.</p>
530 <h2 id="private">private</h2>
532 <p>If you set <code>"private": true</code> in your package.json, then npm will refuse
535 <p>This is a way to prevent accidental publication of private repositories.
536 If you would like to ensure that a given package is only ever published
537 to a specific registry (for example, an internal registry),
538 then use the <code>publishConfig</code> hash described below
539 to override the <code>registry</code> config param at publish-time.</p>
541 <h2 id="publishConfig">publishConfig</h2>
543 <p>This is a set of config values that will be used at publish-time. It's
544 especially handy if you want to set the tag or registry, so that you can
545 ensure that a given package is not tagged with "latest" or published to
546 the global public registry by default.</p>
548 <p>Any config values can be overridden, but of course only "tag" and
549 "registry" probably matter for the purposes of publishing.</p>
551 <p>See <code><a href="../misc/npm-config.html">npm-config(7)</a></code> to see the list of config options that can be
554 <h2 id="SEE-ALSO">SEE ALSO</h2>
556 <ul><li><a href="../misc/semver.html">semver(7)</a></li><li><a href="../cli/npm-init.html">npm-init(1)</a></li><li><a href="../cli/npm-version.html">npm-version(1)</a></li><li><a href="../cli/npm-config.html">npm-config(1)</a></li><li><a href="../misc/npm-config.html">npm-config(7)</a></li><li><a href="../cli/npm-help.html">npm-help(1)</a></li><li><a href="../misc/npm-faq.html">npm-faq(7)</a></li><li><a href="../cli/npm-install.html">npm-install(1)</a></li><li><a href="../cli/npm-publish.html">npm-publish(1)</a></li><li><a href="../cli/npm-rm.html">npm-rm(1)</a></li></ul>
558 <p id="footer">package.json — npm@1.3.17</p>
561 var wrapper = document.getElementById("wrapper")
562 var els = Array.prototype.slice.call(wrapper.getElementsByTagName("*"), 0)
563 .filter(function (el) {
564 return el.parentNode === wrapper
565 && el.tagName.match(/H[1-6]/)
569 , toc = document.createElement("ul")
570 toc.innerHTML = els.map(function (el) {
571 var i = el.tagName.charAt(1)
581 out += "<li><a href='#" + el.id + "'>" +
582 ( el.innerText || el.text || el.innerHTML)
587 document.body.appendChild(toc)