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 less than or equal to 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](https://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](https://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 a string value like this one:
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:
190 * `CHANGES` / `CHANGELOG` / `HISTORY` (any casing and file extension)
191 * `LICENSE` / `LICENCE`
192 * The file in the "main" field
194 Conversely, some files are always ignored:
211 The main field is a module ID that is the primary entry point to your program.
212 That is, if your package is named `foo`, and a user installs it, and then does
213 `require("foo")`, then your main module's exports object will be returned.
215 This should be a module ID relative to the root of your package folder.
217 For most modules, it makes the most sense to have a main script and often not
222 A lot of packages have one or more executable files that they'd like to
223 install into the PATH. npm makes this pretty easy (in fact, it uses this
224 feature to install the "npm" executable.)
226 To use this, supply a `bin` field in your package.json which is a map of
227 command name to local file name. On install, npm will symlink that file into
228 `prefix/bin` for global installs, or `./node_modules/.bin/` for local
232 For example, myapp could have this:
234 { "bin" : { "myapp" : "./cli.js" } }
236 So, when you install myapp, it'll create a symlink from the `cli.js` script to
237 `/usr/local/bin/myapp`.
239 If you have a single executable, and its name should be the name
240 of the package, then you can just supply it as a string. For example:
242 { "name": "my-program"
244 , "bin": "./path/to/program" }
246 would be the same as this:
248 { "name": "my-program"
250 , "bin" : { "my-program" : "./path/to/program" } }
252 Please make sure that your file(s) referenced in `bin` starts with
253 `#!/usr/bin/env node`, otherwise the scripts are started without the node
258 Specify either a single file or an array of filenames to put in place for the
259 `man` program to find.
261 If only a single file is provided, then it's installed such that it is the
262 result from `man <pkgname>`, regardless of its actual filename. For example:
265 , "version" : "1.2.3"
266 , "description" : "A packaged foo fooer for fooing foos"
268 , "man" : "./man/doc.1"
271 would link the `./man/doc.1` file in such that it is the target for `man foo`
273 If the filename doesn't start with the package name, then it's prefixed.
277 , "version" : "1.2.3"
278 , "description" : "A packaged foo fooer for fooing foos"
280 , "man" : [ "./man/foo.1", "./man/bar.1" ]
283 will create files to do `man foo` and `man foo-bar`.
285 Man files must end with a number, and optionally a `.gz` suffix if they are
286 compressed. The number dictates which man section the file is installed into.
289 , "version" : "1.2.3"
290 , "description" : "A packaged foo fooer for fooing foos"
292 , "man" : [ "./man/foo.1", "./man/foo.2" ]
295 will create entries for `man foo` and `man 2 foo`
299 The CommonJS [Packages](http://wiki.commonjs.org/wiki/Packages/1.0) spec details a
300 few ways that you can indicate the structure of your package using a `directories`
301 object. If you look at [npm's package.json](https://registry.npmjs.org/npm/latest),
302 you'll see that it has directories for doc, lib, and man.
304 In the future, this information may be used in other creative ways.
308 Tell people where the bulk of your library is. Nothing special is done
309 with the lib folder in any way, but it's useful meta info.
313 If you specify a `bin` directory in `directories.bin`, all the files in
314 that folder will be added.
316 Because of the way the `bin` directive works, specifying both a
317 `bin` path and setting `directories.bin` is an error. If you want to
318 specify individual files, use `bin`, and for all the files in an
319 existing `bin` directory, use `directories.bin`.
323 A folder that is full of man pages. Sugar to generate a "man" array by
328 Put markdown files in here. Eventually, these will be displayed nicely,
331 ### directories.example
333 Put example scripts in here. Someday, it might be exposed in some clever way.
337 Put your tests in here. It is currently not exposed, but it might be in the
342 Specify the place where your code lives. This is helpful for people who
343 want to contribute. If the git repo is on GitHub, then the `npm docs`
344 command will be able to find you.
350 , "url" : "https://github.com/npm/npm.git"
355 , "url" : "https://v8.googlecode.com/svn/trunk/"
358 The URL should be a publicly available (perhaps read-only) url that can be handed
359 directly to a VCS program without any modification. It should not be a url to an
360 html project page that you put in your browser. It's for computers.
362 For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same
363 shortcut syntax you use for `npm install`:
365 "repository": "npm/npm"
367 "repository": "gist:11081aaa281"
369 "repository": "bitbucket:example/repo"
371 "repository": "gitlab:another/repo"
375 The "scripts" property is a dictionary containing script commands that are run
376 at various times in the lifecycle of your package. The key is the lifecycle
377 event, and the value is the command to run at that point.
379 See `npm-scripts(7)` to find out more about writing package scripts.
383 A "config" object can be used to set configuration parameters used in package
384 scripts that persist across upgrades. For instance, if a package had the
388 , "config" : { "port" : "8080" } }
390 and then had a "start" command that then referenced the
391 `npm_package_config_port` environment variable, then the user could
392 override that by doing `npm config set foo:port 8001`.
394 See `npm-config(7)` and `npm-scripts(7)` for more on package
399 Dependencies are specified in a simple object that maps a package name to a
400 version range. The version range is a string which has one or more
401 space-separated descriptors. Dependencies can also be identified with a
404 **Please do not put test harnesses or transpilers in your
405 `dependencies` object.** See `devDependencies`, below.
407 See semver(7) for more details about specifying version ranges.
409 * `version` Must match `version` exactly
410 * `>version` Must be greater than `version`
414 * `~version` "Approximately equivalent to version" See semver(7)
415 * `^version` "Compatible with version" See semver(7)
416 * `1.2.x` 1.2.0, 1.2.1, etc., but not 1.3.0
417 * `http://...` See 'URLs as Dependencies' below
418 * `*` Matches any version
419 * `""` (just an empty string) Same as `*`
420 * `version1 - version2` Same as `>=version1 <=version2`.
421 * `range1 || range2` Passes if either range1 or range2 are satisfied.
422 * `git...` See 'Git URLs as Dependencies' below
423 * `user/repo` See 'GitHub URLs' below
424 * `tag` A specific version tagged and published as `tag` See `npm-tag(1)`
425 * `path/path/path` See [Local Paths](#local-paths) below
427 For example, these are all valid:
430 { "foo" : "1.0.0 - 2.9999.9999"
431 , "bar" : ">=1.0.2 <2.1.2"
432 , "baz" : ">1.0.2 <=2.3.4"
434 , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
435 , "asd" : "http://asdf.com/asdf.tar.gz"
441 , "dyl" : "file:../dyl"
445 ### URLs as Dependencies
447 You may specify a tarball URL in place of a version range.
449 This tarball will be downloaded and installed locally to your package at
452 ### Git URLs as Dependencies
454 Git urls can be of the form:
456 git://github.com/user/project.git#commit-ish
457 git+ssh://user@hostname:project.git#commit-ish
458 git+ssh://user@hostname/project.git#commit-ish
459 git+http://user@hostname/project/blah.git#commit-ish
460 git+https://user@hostname/project/blah.git#commit-ish
462 The `commit-ish` can be any tag, sha, or branch which can be supplied as
463 an argument to `git checkout`. The default is `master`.
467 As of version 1.1.65, you can refer to GitHub urls as just "foo":
468 "user/foo-project". Just as with git URLs, a `commit-ish` suffix can be
469 included. For example:
475 "express": "visionmedia/express",
476 "mocha": "visionmedia/mocha#4727d357ea"
482 As of version 2.0.0 you can provide a path to a local directory that contains a
483 package. Local paths can be saved using `npm install --save`, using any of
491 in which case they will be normalized to a relative path and added to your
492 `package.json`. For example:
497 "bar": "file:../foo/bar"
501 This feature is helpful for local offline development and creating
502 tests that require npm installing where you don't want to hit an
503 external server, but should not be used when publishing packages
504 to the public registry.
508 If someone is planning on downloading and using your module in their
509 program, then they probably don't want or need to download and build
510 the external test or documentation framework that you use.
512 In this case, it's best to map these additional items in a `devDependencies`
515 These things will be installed when doing `npm link` or `npm install`
516 from the root of a package, and can be managed like any other npm
517 configuration param. See `npm-config(7)` for more on the topic.
519 For build steps that are not platform-specific, such as compiling
520 CoffeeScript or other languages to JavaScript, use the `prepublish`
521 script to do this, and make the required package a devDependency.
525 { "name": "ethopia-waza",
526 "description": "a delightfully fruity coffee varietal",
529 "coffee-script": "~1.6.3"
532 "prepublish": "coffee -o lib/ -c src/waza.coffee"
534 "main": "lib/waza.js"
537 The `prepublish` script will be run before publishing, so that users
538 can consume the functionality without requiring them to compile it
539 themselves. In dev mode (ie, locally running `npm install`), it'll
540 run this script as well, so that you can test it easily.
544 In some cases, you want to express the compatibility of your package with a
545 host tool or library, while not necessarily doing a `require` of this host.
546 This is usually referred to as a *plugin*. Notably, your module may be exposing
547 a specific interface, expected and specified by the host documentation.
554 "peerDependencies": {
559 This ensures your package `tea-latte` can be installed *along* with the second
560 major version of the host package `tea` only. `npm install tea-latte` could
561 possibly yield the following dependency graph:
566 **NOTE: npm versions 1 and 2 will automatically install `peerDependencies` if
567 they are not explicitly depended upon higher in the dependency tree. In the
568 next major version of npm (npm@3), this will no longer be the case. You will
569 receive a warning that the peerDependency is not installed instead.** The
570 behavior in npms 1 & 2 was frequently confusing and could easily put you into
571 dependency hell, a situation that npm is designed to avoid as much as possible.
573 Trying to install another plugin with a conflicting requirement will cause an
574 error. For this reason, make sure your plugin requirement is as broad as
575 possible, and not to lock it down to specific patch versions.
577 Assuming the host complies with [semver](http://semver.org/), only changes in
578 the host package's major version will break your plugin. Thus, if you've worked
579 with every 1.x version of the host package, use `"^1.0"` or `"1.x"` to express
580 this. If you depend on features introduced in 1.5.2, use `">= 1.5.2 < 2"`.
582 ## bundledDependencies
584 This defines an array of package names that will be bundled when publishing the package.
586 In cases where you need to preserve npm packages locally or have them available through a single file download, you can bundle the packages in a tarball file by specifying the package names in the `bundledDependencies` array and executing `npm pack`.
589 If we define a package.json like this:
593 "name": "awesome-web-framework",
595 "bundledDependencies": [
596 'renderized', 'super-streams'
600 we can obtain `awesome-web-framework-1.0.0.tgz` file by running `npm pack`. This file contains the dependencies `renderized` and `super-streams` which can be installed in a new project by executing `npm install awesome-web-framework-1.0.0.tgz`.
602 If this is spelled `"bundleDependencies"`, then that is also honored.
604 ## optionalDependencies
606 If a dependency can be used, but you would like npm to proceed if it cannot be
607 found or fails to install, then you may put it in the `optionalDependencies`
608 object. This is a map of package name to version or url, just like the
609 `dependencies` object. The difference is that build failures do not cause
610 installation to fail.
612 It is still your program's responsibility to handle the lack of the
613 dependency. For example, something like this:
616 var foo = require('foo')
617 var fooVersion = require('foo/package.json').version
621 if ( notGoodFooVersion(fooVersion) ) {
625 // .. then later in your program ..
631 Entries in `optionalDependencies` will override entries of the same name in
632 `dependencies`, so it's usually best to only put in one place.
636 You can specify the version of node that your stuff works on:
638 { "engines" : { "node" : ">=0.10.3 <0.12" } }
640 And, like with dependencies, if you don't specify the version (or if you
641 specify "\*" as the version), then any version of node will do.
643 If you specify an "engines" field, then npm will require that "node" be
644 somewhere on that list. If "engines" is omitted, then npm will just assume
645 that it works on node.
647 You can also use the "engines" field to specify which versions of npm
648 are capable of properly installing your program. For example:
650 { "engines" : { "npm" : "~1.0.20" } }
652 Unless the user has set the `engine-strict` config flag, this
653 field is advisory only will produce warnings when your package is installed as a dependency.
657 **NOTE: This feature is deprecated and will be removed in npm 3.0.0.**
659 If you are sure that your module will *definitely not* run properly on
660 versions of Node/npm other than those specified in the `engines` object,
661 then you can set `"engineStrict": true` in your package.json file.
662 This will override the user's `engine-strict` config setting.
664 Please do not do this unless you are really very very sure. If your
665 engines object is something overly restrictive, you can quite easily and
666 inadvertently lock yourself into obscurity and prevent your users from
667 updating to new versions of Node. Consider this choice carefully.
671 You can specify which operating systems your
674 "os" : [ "darwin", "linux" ]
676 You can also blacklist instead of whitelist operating systems,
677 just prepend the blacklisted os with a '!':
681 The host operating system is determined by `process.platform`
683 It is allowed to both blacklist, and whitelist, although there isn't any
684 good reason to do this.
688 If your code only runs on certain cpu architectures,
689 you can specify which ones.
691 "cpu" : [ "x64", "ia32" ]
693 Like the `os` option, you can also blacklist architectures:
695 "cpu" : [ "!arm", "!mips" ]
697 The host architecture is determined by `process.arch`
701 If your package is primarily a command-line application that should be
702 installed globally, then set this value to `true` to provide a warning
703 if it is installed locally.
705 It doesn't actually prevent users from installing it locally, but it
706 does help prevent some confusion if it doesn't work as expected.
710 If you set `"private": true` in your package.json, then npm will refuse
713 This is a way to prevent accidental publication of private repositories. If
714 you would like to ensure that a given package is only ever published to a
715 specific registry (for example, an internal registry), then use the
716 `publishConfig` dictionary described below to override the `registry` config
717 param at publish-time.
721 This is a set of config values that will be used at publish-time. It's
722 especially handy if you want to set the tag, registry or access, so that
723 you can ensure that a given package is not tagged with "latest", published
724 to the global public registry or that a scoped module is private by default.
726 Any config values can be overridden, but of course only "tag", "registry" and
727 "access" probably matter for the purposes of publishing.
729 See `npm-config(7)` to see the list of config options that can be
734 npm will default some values based on package contents.
736 * `"scripts": {"start": "node server.js"}`
738 If there is a `server.js` file in the root of your package, then npm
739 will default the `start` command to `node server.js`.
741 * `"scripts":{"install": "node-gyp rebuild"}`
743 If there is a `binding.gyp` file in the root of your package and you have not defined an `install` or `preinstall` script, npm will
744 default the `install` command to compile using node-gyp.
746 * `"contributors": [...]`
748 If there is an `AUTHORS` file in the root of your package, npm will
749 treat each line as a `Name <email> (url)` format, where email and url
750 are optional. Lines which start with a `#` or are blank, will be