1 package.json(5) -- Specifics of npm's package.json handling
2 ===========================================================
6 This document is all you need to know about what's required in your package.json
7 file. It must be actual JSON, not just a JavaScript object literal.
9 A lot of the behavior described in this document is affected by the config
10 settings described in `npm-config(7)`.
14 The *most* important things in your package.json are the name and version fields.
15 Those are actually required, and your package won't install without
16 them. The name and version together form an identifier that is assumed
17 to be completely unique. Changes to the package should come along with
18 changes to the version.
20 The name is what your thing is called.
24 * The name must be shorter than 214 characters. This includes the scope for
26 * The name can't start with a dot or an underscore.
27 * New packages must not have uppercase letters in the name.
28 * The name ends up being part of a URL, an argument on the command line, and a
29 folder name. Therefore, the name can't contain any non-URL-safe characters.
33 * Don't use the same name as a core Node module.
34 * Don't put "js" or "node" in the name. It's assumed that it's js, since you're
35 writing a package.json file, and you can specify the engine using the "engines"
37 * The name will probably be passed as an argument to require(), so it should
38 be something short, but also reasonably descriptive.
39 * You may want to check the npm registry to see if there's something by that name
40 already, before you get too attached to it. <https://www.npmjs.com/>
42 A name can be optionally prefixed by a scope, e.g. `@myorg/mypackage`. See
43 `npm-scope(7)` for more detail.
47 The *most* important things in your package.json are the name and version fields.
48 Those are actually required, and your package won't install without
49 them. The name and version together form an identifier that is assumed
50 to be completely unique. Changes to the package should come along with
51 changes to the version.
53 Version must be parseable by
54 [node-semver](https://github.com/isaacs/node-semver), which is bundled
55 with npm as a dependency. (`npm install semver` to use it yourself.)
57 More on version numbers and ranges at semver(7).
61 Put a description in it. It's a string. This helps people discover your
62 package, as it's listed in `npm search`.
66 Put keywords in it. It's an array of strings. This helps people
67 discover your package as it's listed in `npm search`.
71 The url to the project homepage.
73 **NOTE**: This is *not* the same as "url". If you put a "url" field,
74 then the registry will think it's a redirection to your package that has
75 been published somewhere else, and spit at you.
77 Literally. Spit. I'm so not kidding.
81 The url to your project's issue tracker and / or the email address to which
82 issues should be reported. These are helpful for people who encounter issues
85 It should look like this:
87 { "url" : "https://github.com/owner/project/issues"
88 , "email" : "project@hostname.com"
91 You can specify either one or both values. If you want to provide only a url,
92 you can specify the value for "bugs" as a simple string instead of an object.
94 If a url is provided, it will be used by the `npm bugs` command.
98 You should specify a license for your package so that people know how they are
99 permitted to use it, and any restrictions you're placing on it.
101 If you're using a common license such as BSD-2-Clause or MIT, add a
102 current SPDX license identifier for the license you're using, like this:
104 { "license" : "BSD-3-Clause" }
106 You can check [the full list of SPDX license IDs](https://spdx.org/licenses/).
107 Ideally you should pick one that is
108 [OSI](http://opensource.org/licenses/alphabetical) approved.
110 If your package is licensed under multiple common licenses, use an [SPDX license
111 expression syntax version 2.0 string](http://npmjs.com/package/spdx), like this:
113 { "license" : "(ISC OR GPL-3.0)" }
115 If you are using a license that hasn't been assigned an SPDX identifier, or if
116 you are using a custom license, use the following valid SPDX expression:
118 { "license" : "SEE LICENSE IN <filename>" }
120 Then include a file named `<filename>` at the top level of the package.
122 Some old packages used license objects or a "licenses" property containing an
123 array of license objects:
125 // Not valid metadata
128 , "url" : "http://opensource.org/licenses/ISC"
132 // Not valid metadata
136 , "url": "http://www.opensource.org/licenses/mit-license.php"
138 , { "type": "Apache-2.0"
139 , "url": "http://opensource.org/licenses/apache2.0.php"
144 Those styles are now deprecated. Instead, use SPDX expressions, like this:
148 { "license": "(MIT OR Apache-2.0)" }
150 Finally, if you do not wish to grant others the right to use a private or
151 unpublished package under any terms:
153 { "license": "UNLICENSED"}
155 Consider also setting `"private": true` to prevent accidental publication.
157 ## people fields: author, contributors
159 The "author" is one person. "contributors" is an array of people. A "person"
160 is an object with a "name" field and optionally "url" and "email", like this:
162 { "name" : "Barney Rubble"
163 , "email" : "b@rubble.com"
164 , "url" : "http://barnyrubble.tumblr.com/"
167 Or you can shorten that all into a single string, and npm will parse it for you:
169 "Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)"
171 Both email and url are optional either way.
173 npm also sets a top-level "maintainers" field with your npm user info.
177 The "files" field is an array of files to include in your project. If
178 you name a folder in the array, then it will also include the files
179 inside that folder. (Unless they would be ignored by another rule.)
181 You can also provide a ".npmignore" file in the root of your package or
182 in subdirectories, which will keep files from being included, even
183 if they would be picked up by the files array. The `.npmignore` file
184 works just like a `.gitignore`.
186 Certain files are always included, regardless of settings:
189 * `README` (and its variants)
190 * `CHANGELOG` (and its variants)
191 * `LICENSE` / `LICENCE`
193 Conversely, some files are always ignored:
208 The main field is a module ID that is the primary entry point to your program.
209 That is, if your package is named `foo`, and a user installs it, and then does
210 `require("foo")`, then your main module's exports object will be returned.
212 This should be a module ID relative to the root of your package folder.
214 For most modules, it makes the most sense to have a main script and often not
219 A lot of packages have one or more executable files that they'd like to
220 install into the PATH. npm makes this pretty easy (in fact, it uses this
221 feature to install the "npm" executable.)
223 To use this, supply a `bin` field in your package.json which is a map of
224 command name to local file name. On install, npm will symlink that file into
225 `prefix/bin` for global installs, or `./node_modules/.bin/` for local
229 For example, myapp could have this:
231 { "bin" : { "myapp" : "./cli.js" } }
233 So, when you install myapp, it'll create a symlink from the `cli.js` script to
234 `/usr/local/bin/myapp`.
236 If you have a single executable, and its name should be the name
237 of the package, then you can just supply it as a string. For example:
239 { "name": "my-program"
241 , "bin": "./path/to/program" }
243 would be the same as this:
245 { "name": "my-program"
247 , "bin" : { "my-program" : "./path/to/program" } }
251 Specify either a single file or an array of filenames to put in place for the
252 `man` program to find.
254 If only a single file is provided, then it's installed such that it is the
255 result from `man <pkgname>`, regardless of its actual filename. For example:
258 , "version" : "1.2.3"
259 , "description" : "A packaged foo fooer for fooing foos"
261 , "man" : "./man/doc.1"
264 would link the `./man/doc.1` file in such that it is the target for `man foo`
266 If the filename doesn't start with the package name, then it's prefixed.
270 , "version" : "1.2.3"
271 , "description" : "A packaged foo fooer for fooing foos"
273 , "man" : [ "./man/foo.1", "./man/bar.1" ]
276 will create files to do `man foo` and `man foo-bar`.
278 Man files must end with a number, and optionally a `.gz` suffix if they are
279 compressed. The number dictates which man section the file is installed into.
282 , "version" : "1.2.3"
283 , "description" : "A packaged foo fooer for fooing foos"
285 , "man" : [ "./man/foo.1", "./man/foo.2" ]
288 will create entries for `man foo` and `man 2 foo`
292 The CommonJS [Packages](http://wiki.commonjs.org/wiki/Packages/1.0) spec details a
293 few ways that you can indicate the structure of your package using a `directories`
294 object. If you look at [npm's package.json](https://registry.npmjs.org/npm/latest),
295 you'll see that it has directories for doc, lib, and man.
297 In the future, this information may be used in other creative ways.
301 Tell people where the bulk of your library is. Nothing special is done
302 with the lib folder in any way, but it's useful meta info.
306 If you specify a `bin` directory in `directories.bin`, all the files in
307 that folder will be added.
309 Because of the way the `bin` directive works, specifying both a
310 `bin` path and setting `directories.bin` is an error. If you want to
311 specify individual files, use `bin`, and for all the files in an
312 existing `bin` directory, use `directories.bin`.
316 A folder that is full of man pages. Sugar to generate a "man" array by
321 Put markdown files in here. Eventually, these will be displayed nicely,
324 ### directories.example
326 Put example scripts in here. Someday, it might be exposed in some clever way.
330 Specify the place where your code lives. This is helpful for people who
331 want to contribute. If the git repo is on GitHub, then the `npm docs`
332 command will be able to find you.
338 , "url" : "https://github.com/npm/npm.git"
343 , "url" : "https://v8.googlecode.com/svn/trunk/"
346 The URL should be a publicly available (perhaps read-only) url that can be handed
347 directly to a VCS program without any modification. It should not be a url to an
348 html project page that you put in your browser. It's for computers.
350 For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
351 shortcut syntax you use for `npm install`:
353 "repository": "npm/npm"
355 "repository": "gist:11081aaa281"
357 "repository": "bitbucket:example/repo"
359 "repository": "gitlab:another/repo"
363 The "scripts" property is a dictionary containing script commands that are run
364 at various times in the lifecycle of your package. The key is the lifecycle
365 event, and the value is the command to run at that point.
367 See `npm-scripts(7)` to find out more about writing package scripts.
371 A "config" object can be used to set configuration parameters used in package
372 scripts that persist across upgrades. For instance, if a package had the
376 , "config" : { "port" : "8080" } }
378 and then had a "start" command that then referenced the
379 `npm_package_config_port` environment variable, then the user could
380 override that by doing `npm config set foo:port 8001`.
382 See `npm-config(7)` and `npm-scripts(7)` for more on package
387 Dependencies are specified in a simple object that maps a package name to a
388 version range. The version range is a string which has one or more
389 space-separated descriptors. Dependencies can also be identified with a
392 **Please do not put test harnesses or transpilers in your
393 `dependencies` object.** See `devDependencies`, below.
395 See semver(7) for more details about specifying version ranges.
397 * `version` Must match `version` exactly
398 * `>version` Must be greater than `version`
402 * `~version` "Approximately equivalent to version" See semver(7)
403 * `^version` "Compatible with version" See semver(7)
404 * `1.2.x` 1.2.0, 1.2.1, etc., but not 1.3.0
405 * `http://...` See 'URLs as Dependencies' below
406 * `*` Matches any version
407 * `""` (just an empty string) Same as `*`
408 * `version1 - version2` Same as `>=version1 <=version2`.
409 * `range1 || range2` Passes if either range1 or range2 are satisfied.
410 * `git...` See 'Git URLs as Dependencies' below
411 * `user/repo` See 'GitHub URLs' below
412 * `tag` A specific version tagged and published as `tag` See `npm-tag(1)`
413 * `path/path/path` See Local Paths below
415 For example, these are all valid:
418 { "foo" : "1.0.0 - 2.9999.9999"
419 , "bar" : ">=1.0.2 <2.1.2"
420 , "baz" : ">1.0.2 <=2.3.4"
422 , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
423 , "asd" : "http://asdf.com/asdf.tar.gz"
429 , "dyl" : "file:../dyl"
433 ### URLs as Dependencies
435 You may specify a tarball URL in place of a version range.
437 This tarball will be downloaded and installed locally to your package at
440 ### Git URLs as Dependencies
442 Git urls can be of the form:
444 git://github.com/user/project.git#commit-ish
445 git+ssh://user@hostname:project.git#commit-ish
446 git+ssh://user@hostname/project.git#commit-ish
447 git+http://user@hostname/project/blah.git#commit-ish
448 git+https://user@hostname/project/blah.git#commit-ish
450 The `commit-ish` can be any tag, sha, or branch which can be supplied as
451 an argument to `git checkout`. The default is `master`.
455 As of version 1.1.65, you can refer to GitHub urls as just "foo":
456 "user/foo-project". Just as with git URLs, a `commit-ish` suffix can be
457 included. For example:
463 "express": "visionmedia/express",
464 "mocha": "visionmedia/mocha#4727d357ea"
470 As of version 2.0.0 you can provide a path to a local directory that contains a
471 package. Local paths can be saved using `npm install --save`, using any of
479 in which case they will be normalized to a relative path and added to your
480 `package.json`. For example:
485 "bar": "file:../foo/bar"
489 This feature is helpful for local offline development and creating
490 tests that require npm installing where you don't want to hit an
491 external server, but should not be used when publishing packages
492 to the public registry.
496 If someone is planning on downloading and using your module in their
497 program, then they probably don't want or need to download and build
498 the external test or documentation framework that you use.
500 In this case, it's best to map these additional items in a `devDependencies`
503 These things will be installed when doing `npm link` or `npm install`
504 from the root of a package, and can be managed like any other npm
505 configuration param. See `npm-config(7)` for more on the topic.
507 For build steps that are not platform-specific, such as compiling
508 CoffeeScript or other languages to JavaScript, use the `prepublish`
509 script to do this, and make the required package a devDependency.
513 { "name": "ethopia-waza",
514 "description": "a delightfully fruity coffee varietal",
517 "coffee-script": "~1.6.3"
520 "prepublish": "coffee -o lib/ -c src/waza.coffee"
522 "main": "lib/waza.js"
525 The `prepublish` script will be run before publishing, so that users
526 can consume the functionality without requiring them to compile it
527 themselves. In dev mode (ie, locally running `npm install`), it'll
528 run this script as well, so that you can test it easily.
532 In some cases, you want to express the compatibility of your package with a
533 host tool or library, while not necessarily doing a `require` of this host.
534 This is usually referred to as a *plugin*. Notably, your module may be exposing
535 a specific interface, expected and specified by the host documentation.
542 "peerDependencies": {
547 This ensures your package `tea-latte` can be installed *along* with the second
548 major version of the host package `tea` only. `npm install tea-latte` could
549 possibly yield the following dependency graph:
554 **NOTE: npm versions 1 and 2 will automatically install `peerDependencies` if
555 they are not explicitly depended upon higher in the dependency tree. In the
556 next major version of npm (npm@3), this will no longer be the case. You will
557 receive a warning that the peerDependency is not installed instead.** The
558 behavior in npms 1 & 2 was frequently confusing and could easily put you into
559 dependency hell, a situation that npm is designed to avoid as much as possible.
561 Trying to install another plugin with a conflicting requirement will cause an
562 error. For this reason, make sure your plugin requirement is as broad as
563 possible, and not to lock it down to specific patch versions.
565 Assuming the host complies with [semver](http://semver.org/), only changes in
566 the host package's major version will break your plugin. Thus, if you've worked
567 with every 1.x version of the host package, use `"^1.0"` or `"1.x"` to express
568 this. If you depend on features introduced in 1.5.2, use `">= 1.5.2 < 2"`.
570 ## bundledDependencies
572 Array of package names that will be bundled when publishing the package.
574 If this is spelled `"bundleDependencies"`, then that is also honored.
576 ## optionalDependencies
578 If a dependency can be used, but you would like npm to proceed if it cannot be
579 found or fails to install, then you may put it in the `optionalDependencies`
580 object. This is a map of package name to version or url, just like the
581 `dependencies` object. The difference is that build failures do not cause
582 installation to fail.
584 It is still your program's responsibility to handle the lack of the
585 dependency. For example, something like this:
588 var foo = require('foo')
589 var fooVersion = require('foo/package.json').version
593 if ( notGoodFooVersion(fooVersion) ) {
597 // .. then later in your program ..
603 Entries in `optionalDependencies` will override entries of the same name in
604 `dependencies`, so it's usually best to only put in one place.
608 You can specify the version of node that your stuff works on:
610 { "engines" : { "node" : ">=0.10.3 <0.12" } }
612 And, like with dependencies, if you don't specify the version (or if you
613 specify "\*" as the version), then any version of node will do.
615 If you specify an "engines" field, then npm will require that "node" be
616 somewhere on that list. If "engines" is omitted, then npm will just assume
617 that it works on node.
619 You can also use the "engines" field to specify which versions of npm
620 are capable of properly installing your program. For example:
622 { "engines" : { "npm" : "~1.0.20" } }
624 Note that, unless the user has set the `engine-strict` config flag, this
625 field is advisory only.
629 **NOTE: This feature is deprecated and will be removed in npm 3.0.0.**
631 If you are sure that your module will *definitely not* run properly on
632 versions of Node/npm other than those specified in the `engines` object,
633 then you can set `"engineStrict": true` in your package.json file.
634 This will override the user's `engine-strict` config setting.
636 Please do not do this unless you are really very very sure. If your
637 engines object is something overly restrictive, you can quite easily and
638 inadvertently lock yourself into obscurity and prevent your users from
639 updating to new versions of Node. Consider this choice carefully.
643 You can specify which operating systems your
646 "os" : [ "darwin", "linux" ]
648 You can also blacklist instead of whitelist operating systems,
649 just prepend the blacklisted os with a '!':
653 The host operating system is determined by `process.platform`
655 It is allowed to both blacklist, and whitelist, although there isn't any
656 good reason to do this.
660 If your code only runs on certain cpu architectures,
661 you can specify which ones.
663 "cpu" : [ "x64", "ia32" ]
665 Like the `os` option, you can also blacklist architectures:
667 "cpu" : [ "!arm", "!mips" ]
669 The host architecture is determined by `process.arch`
673 If your package is primarily a command-line application that should be
674 installed globally, then set this value to `true` to provide a warning
675 if it is installed locally.
677 It doesn't actually prevent users from installing it locally, but it
678 does help prevent some confusion if it doesn't work as expected.
682 If you set `"private": true` in your package.json, then npm will refuse
685 This is a way to prevent accidental publication of private repositories. If
686 you would like to ensure that a given package is only ever published to a
687 specific registry (for example, an internal registry), then use the
688 `publishConfig` dictionary described below to override the `registry` config
689 param at publish-time.
693 This is a set of config values that will be used at publish-time. It's
694 especially handy if you want to set the tag, registry or access, so that
695 you can ensure that a given package is not tagged with "latest", published
696 to the global public registry or that a scoped module is private by default.
698 Any config values can be overridden, but of course only "tag", "registry" and
699 "access" probably matter for the purposes of publishing.
701 See `npm-config(7)` to see the list of config options that can be
706 npm will default some values based on package contents.
708 * `"scripts": {"start": "node server.js"}`
710 If there is a `server.js` file in the root of your package, then npm
711 will default the `start` command to `node server.js`.
713 * `"scripts":{"preinstall": "node-gyp rebuild"}`
715 If there is a `binding.gyp` file in the root of your package, npm will
716 default the `preinstall` command to compile using node-gyp.
718 * `"contributors": [...]`
720 If there is an `AUTHORS` file in the root of your package, npm will
721 treat each line as a `Name <email> (url)` format, where email and url
722 are optional. Lines which start with a `#` or are blank, will be