• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html><html><head>
2<meta charset="utf-8">
3<title>package.json</title>
4<style>
5body {
6    background-color: #ffffff;
7    color: #24292e;
8
9    margin: 0;
10
11    line-height: 1.5;
12
13    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
14}
15#rainbar {
16    height: 10px;
17    background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
18}
19
20a {
21    text-decoration: none;
22    color: #0366d6;
23}
24a:hover {
25    text-decoration: underline;
26}
27
28pre {
29    margin: 1em 0px;
30    padding: 1em;
31    border: solid 1px #e1e4e8;
32    border-radius: 6px;
33
34    display: block;
35    overflow: auto;
36
37    white-space: pre;
38
39    background-color: #f6f8fa;
40    color: #393a34;
41}
42code {
43    font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
44    font-size: 85%;
45    padding: 0.2em 0.4em;
46    background-color: #f6f8fa;
47    color: #393a34;
48}
49pre > code {
50    padding: 0;
51    background-color: inherit;
52    color: inherit;
53}
54h1, h2, h3 {
55    font-weight: 600;
56}
57
58#logobar {
59    background-color: #333333;
60    margin: 0 auto;
61    padding: 1em 4em;
62}
63#logobar .logo {
64    float: left;
65}
66#logobar .title {
67    font-weight: 600;
68    color: #dddddd;
69    float: left;
70    margin: 5px 0 0 1em;
71}
72#logobar:after {
73    content: "";
74    display: block;
75    clear: both;
76}
77
78#content {
79    margin: 0 auto;
80    padding: 0 4em;
81}
82
83#table_of_contents > h2 {
84    font-size: 1.17em;
85}
86#table_of_contents ul:first-child {
87    border: solid 1px #e1e4e8;
88    border-radius: 6px;
89    padding: 1em;
90    background-color: #f6f8fa;
91    color: #393a34;
92}
93#table_of_contents ul {
94    list-style-type: none;
95    padding-left: 1.5em;
96}
97#table_of_contents li {
98    font-size: 0.9em;
99}
100#table_of_contents li a {
101    color: #000000;
102}
103
104header.title {
105    border-bottom: solid 1px #e1e4e8;
106}
107header.title > h1 {
108    margin-bottom: 0.25em;
109}
110header.title > .description {
111    display: block;
112    margin-bottom: 0.5em;
113    line-height: 1;
114}
115
116footer#edit {
117    border-top: solid 1px #e1e4e8;
118    margin: 3em 0 4em 0;
119    padding-top: 2em;
120}
121</style>
122</head>
123<body>
124<div id="banner">
125<div id="rainbar"></div>
126<div id="logobar">
127<svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
128<polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
129<polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
130</svg>
131<div class="title">
132npm command-line interface
133</div>
134</div>
135</div>
136
137<section id="content">
138<header class="title">
139<h1 id="packagejson">package.json</h1>
140<span class="description">Specifics of npm's package.json handling</span>
141</header>
142
143<section id="table_of_contents">
144<h2 id="table-of-contents">Table of contents</h2>
145<div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#name">name</a></li><li><a href="#version">version</a></li><li><a href="#description2">description</a></li><li><a href="#keywords">keywords</a></li><li><a href="#homepage">homepage</a></li><li><a href="#bugs">bugs</a></li><li><a href="#license">license</a></li><li><a href="#people-fields-author-contributors">people fields: author, contributors</a></li><li><a href="#funding">funding</a></li><li><a href="#files">files</a></li><li><a href="#main">main</a></li><li><a href="#browser">browser</a></li><li><a href="#bin">bin</a></li><li><a href="#man">man</a></li><li><a href="#directories">directories</a></li><ul><li><a href="#directoriesbin">directories.bin</a></li><li><a href="#directoriesman">directories.man</a></li></ul><li><a href="#repository">repository</a></li><li><a href="#scripts">scripts</a></li><li><a href="#config">config</a></li><li><a href="#dependencies">dependencies</a></li><ul><li><a href="#urls-as-dependencies">URLs as Dependencies</a></li><li><a href="#git-urls-as-dependencies">Git URLs as Dependencies</a></li><li><a href="#github-urls">GitHub URLs</a></li><li><a href="#local-paths">Local Paths</a></li></ul><li><a href="#devdependencies">devDependencies</a></li><li><a href="#peerdependencies">peerDependencies</a></li><li><a href="#peerdependenciesmeta">peerDependenciesMeta</a></li><li><a href="#bundledependencies">bundleDependencies</a></li><li><a href="#optionaldependencies">optionalDependencies</a></li><li><a href="#overrides">overrides</a></li><li><a href="#engines">engines</a></li><li><a href="#os">os</a></li><li><a href="#cpu">cpu</a></li><li><a href="#private">private</a></li><li><a href="#publishconfig">publishConfig</a></li><li><a href="#workspaces">workspaces</a></li><li><a href="#default-values">DEFAULT VALUES</a></li><li><a href="#see-also">SEE ALSO</a></li></ul></div>
146</section>
147
148<div id="_content"><h3 id="description">Description</h3>
149<p>This document is all you need to know about what's required in your
150package.json file.  It must be actual JSON, not just a JavaScript object
151literal.</p>
152<p>A lot of the behavior described in this document is affected by the config
153settings described in <a href="../using-npm/config.html"><code>config</code></a>.</p>
154<h3 id="name">name</h3>
155<p>If you plan to publish your package, the <em>most</em> important things in your
156package.json are the name and version fields as they will be required. The
157name and version together form an identifier that is assumed to be
158completely unique.  Changes to the package should come along with changes
159to the version. If you don't plan to publish your package, the name and
160version fields are optional.</p>
161<p>The name is what your thing is called.</p>
162<p>Some rules:</p>
163<ul>
164<li>The name must be less than or equal to 214 characters. This includes the
165scope for scoped packages.</li>
166<li>The names of scoped packages can begin with a dot or an underscore. This
167is not permitted without a scope.</li>
168<li>New packages must not have uppercase letters in the name.</li>
169<li>The name ends up being part of a URL, an argument on the command line,
170and a folder name. Therefore, the name can't contain any non-URL-safe
171characters.</li>
172</ul>
173<p>Some tips:</p>
174<ul>
175<li>Don't use the same name as a core Node module.</li>
176<li>Don't put "js" or "node" in the name.  It's assumed that it's js, since
177you're writing a package.json file, and you can specify the engine using
178the "engines" field.  (See below.)</li>
179<li>The name will probably be passed as an argument to require(), so it
180should be something short, but also reasonably descriptive.</li>
181<li>You may want to check the npm registry to see if there's something by
182that name already, before you get too attached to it.
183<a href="https://www.npmjs.com/">https://www.npmjs.com/</a></li>
184</ul>
185<p>A name can be optionally prefixed by a scope, e.g. <code>@myorg/mypackage</code>. See
186<a href="../using-npm/scope.html"><code>scope</code></a> for more detail.</p>
187<h3 id="version">version</h3>
188<p>If you plan to publish your package, the <em>most</em> important things in your
189package.json are the name and version fields as they will be required. The
190name and version together form an identifier that is assumed to be
191completely unique.  Changes to the package should come along with changes
192to the version. If you don't plan to publish your package, the name and
193version fields are optional.</p>
194<p>Version must be parseable by
195<a href="https://github.com/npm/node-semver">node-semver</a>, which is bundled with
196npm as a dependency.  (<code>npm install semver</code> to use it yourself.)</p>
197<h3 id="description2">description</h3>
198<p>Put a description in it.  It's a string.  This helps people discover your
199package, as it's listed in <code>npm search</code>.</p>
200<h3 id="keywords">keywords</h3>
201<p>Put keywords in it.  It's an array of strings.  This helps people discover
202your package as it's listed in <code>npm search</code>.</p>
203<h3 id="homepage">homepage</h3>
204<p>The url to the project homepage.</p>
205<p>Example:</p>
206<pre><code class="language-json">"homepage": "https://github.com/owner/project#readme"
207</code></pre>
208<h3 id="bugs">bugs</h3>
209<p>The url to your project's issue tracker and / or the email address to which
210issues should be reported. These are helpful for people who encounter
211issues with your package.</p>
212<p>It should look like this:</p>
213<pre><code class="language-json">{
214  "bugs": {
215    "url": "https://github.com/owner/project/issues",
216    "email": "project@hostname.com"
217  }
218}
219</code></pre>
220<p>You can specify either one or both values. If you want to provide only a
221url, you can specify the value for "bugs" as a simple string instead of an
222object.</p>
223<p>If a url is provided, it will be used by the <code>npm bugs</code> command.</p>
224<h3 id="license">license</h3>
225<p>You should specify a license for your package so that people know how they
226are permitted to use it, and any restrictions you're placing on it.</p>
227<p>If you're using a common license such as BSD-2-Clause or MIT, add a current
228SPDX license identifier for the license you're using, like this:</p>
229<pre><code class="language-json">{
230  "license" : "BSD-3-Clause"
231}
232</code></pre>
233<p>You can check <a href="https://spdx.org/licenses/">the full list of SPDX license
234IDs</a>.  Ideally you should pick one that is
235<a href="https://opensource.org/licenses/">OSI</a> approved.</p>
236<p>If your package is licensed under multiple common licenses, use an <a href="https://spdx.dev/specifications/">SPDX
237license expression syntax version 2.0
238string</a>, like this:</p>
239<pre><code class="language-json">{
240  "license" : "(ISC OR GPL-3.0)"
241}
242</code></pre>
243<p>If you are using a license that hasn't been assigned an SPDX identifier, or if
244you are using a custom license, use a string value like this one:</p>
245<pre><code class="language-json">{
246  "license" : "SEE LICENSE IN &lt;filename&gt;"
247}
248</code></pre>
249<p>Then include a file named <code>&lt;filename&gt;</code> at the top level of the package.</p>
250<p>Some old packages used license objects or a "licenses" property containing
251an array of license objects:</p>
252<pre><code class="language-json">// Not valid metadata
253{
254  "license" : {
255    "type" : "ISC",
256    "url" : "https://opensource.org/licenses/ISC"
257  }
258}
259
260// Not valid metadata
261{
262  "licenses" : [
263    {
264      "type": "MIT",
265      "url": "https://www.opensource.org/licenses/mit-license.php"
266    },
267    {
268      "type": "Apache-2.0",
269      "url": "https://opensource.org/licenses/apache2.0.php"
270    }
271  ]
272}
273</code></pre>
274<p>Those styles are now deprecated. Instead, use SPDX expressions, like this:</p>
275<pre><code class="language-json">{
276  "license": "ISC"
277}
278</code></pre>
279<pre><code class="language-json">{
280  "license": "(MIT OR Apache-2.0)"
281}
282</code></pre>
283<p>Finally, if you do not wish to grant others the right to use a private or
284unpublished package under any terms:</p>
285<pre><code class="language-json">{
286  "license": "UNLICENSED"
287}
288</code></pre>
289<p>Consider also setting <code>"private": true</code> to prevent accidental publication.</p>
290<h3 id="people-fields-author-contributors">people fields: author, contributors</h3>
291<p>The "author" is one person.  "contributors" is an array of people.  A
292"person" is an object with a "name" field and optionally "url" and "email",
293like this:</p>
294<pre><code class="language-json">{
295  "name" : "Barney Rubble",
296  "email" : "b@rubble.com",
297  "url" : "http://barnyrubble.tumblr.com/"
298}
299</code></pre>
300<p>Or you can shorten that all into a single string, and npm will parse it for
301you:</p>
302<pre><code class="language-json">{
303  "author": "Barney Rubble &lt;b@rubble.com&gt; (http://barnyrubble.tumblr.com/)"
304}
305</code></pre>
306<p>Both email and url are optional either way.</p>
307<p>npm also sets a top-level "maintainers" field with your npm user info.</p>
308<h3 id="funding">funding</h3>
309<p>You can specify an object containing a URL that provides up-to-date
310information about ways to help fund development of your package, or a
311string URL, or an array of these:</p>
312<pre><code class="language-json">{
313  "funding": {
314    "type" : "individual",
315    "url" : "http://example.com/donate"
316  },
317
318  "funding": {
319    "type" : "patreon",
320    "url" : "https://www.patreon.com/my-account"
321  },
322
323  "funding": "http://example.com/donate",
324
325  "funding": [
326    {
327      "type" : "individual",
328      "url" : "http://example.com/donate"
329    },
330    "http://example.com/donateAlso",
331    {
332      "type" : "patreon",
333      "url" : "https://www.patreon.com/my-account"
334    }
335  ]
336}
337</code></pre>
338<p>Users can use the <code>npm fund</code> subcommand to list the <code>funding</code> URLs of all
339dependencies of their project, direct and indirect. A shortcut to visit
340each funding url is also available when providing the project name such as:
341<code>npm fund &lt;projectname&gt;</code> (when there are multiple URLs, the first one will
342be visited)</p>
343<h3 id="files">files</h3>
344<p>The optional <code>files</code> field is an array of file patterns that describes the
345entries to be included when your package is installed as a dependency. File
346patterns follow a similar syntax to <code>.gitignore</code>, but reversed: including a
347file, directory, or glob pattern (<code>*</code>, <code>**/*</code>, and such) will make it so
348that file is included in the tarball when it's packed. Omitting the field
349will make it default to <code>["*"]</code>, which means it will include all files.</p>
350<p>Some special files and directories are also included or excluded regardless
351of whether they exist in the <code>files</code> array (see below).</p>
352<p>You can also provide a <code>.npmignore</code> file in the root of your package or in
353subdirectories, which will keep files from being included. At the root of
354your package it will not override the "files" field, but in subdirectories
355it will. The <code>.npmignore</code> file works just like a <code>.gitignore</code>. If there is
356a <code>.gitignore</code> file, and <code>.npmignore</code> is missing, <code>.gitignore</code>'s contents
357will be used instead.</p>
358<p>Certain files are always included, regardless of settings:</p>
359<ul>
360<li><code>package.json</code></li>
361<li><code>README</code></li>
362<li><code>LICENSE</code> / <code>LICENCE</code></li>
363<li>The file in the "main" field</li>
364<li>The file(s) in the "bin" field</li>
365</ul>
366<p><code>README</code> &amp; <code>LICENSE</code> can have any case and extension.</p>
367<p>Some files are always ignored by default:</p>
368<ul>
369<li><code>*.orig</code></li>
370<li><code>.*.swp</code></li>
371<li><code>.DS_Store</code></li>
372<li><code>._*</code></li>
373<li><code>.git</code></li>
374<li><code>.hg</code></li>
375<li><code>.lock-wscript</code></li>
376<li><code>.npmrc</code></li>
377<li><code>.svn</code></li>
378<li><code>.wafpickle-N</code></li>
379<li><code>CVS</code></li>
380<li><code>config.gypi</code></li>
381<li><code>node_modules</code></li>
382<li><code>npm-debug.log</code></li>
383<li><code>package-lock.json</code> (use
384<a href="../configuring-npm/npm-shrinkwrap-json.html"><code>npm-shrinkwrap.json</code></a>
385if you wish it to be published)</li>
386<li><code>pnpm-lock.yaml</code></li>
387<li><code>yarn.lock</code></li>
388</ul>
389<p>Most of these ignored files can be included specifically if included in
390the <code>files</code> globs.  Exceptions to this are:</p>
391<ul>
392<li><code>.git</code></li>
393<li><code>.npmrc</code></li>
394<li><code>node_modules</code></li>
395<li><code>package-lock.json</code></li>
396<li><code>pnpm-lock.yaml</code></li>
397<li><code>yarn.lock</code></li>
398</ul>
399<p>These can not be included.</p>
400<h3 id="main">main</h3>
401<p>The main field is a module ID that is the primary entry point to your
402program.  That is, if your package is named <code>foo</code>, and a user installs it,
403and then does <code>require("foo")</code>, then your main module's exports object will
404be returned.</p>
405<p>This should be a module relative to the root of your package folder.</p>
406<p>For most modules, it makes the most sense to have a main script and often
407not much else.</p>
408<p>If <code>main</code> is not set, it defaults to <code>index.js</code> in the package's root folder.</p>
409<h3 id="browser">browser</h3>
410<p>If your module is meant to be used client-side the browser field should be
411used instead of the main field. This is helpful to hint users that it might
412rely on primitives that aren't available in Node.js modules. (e.g.
413<code>window</code>)</p>
414<h3 id="bin">bin</h3>
415<p>A lot of packages have one or more executable files that they'd like to
416install into the PATH. npm makes this pretty easy (in fact, it uses this
417feature to install the "npm" executable.)</p>
418<p>To use this, supply a <code>bin</code> field in your package.json which is a map of
419command name to local file name. When this package is installed globally,
420that file will be either linked inside the global bins directory or
421a cmd (Windows Command File) will be created which executes the specified
422file in the <code>bin</code> field, so it is available to run by <code>name</code> or <code>name.cmd</code> (on
423Windows PowerShell). When this package is installed as a dependency in another
424package, the file will be linked where it will be available to that package
425either directly by <code>npm exec</code> or by name in other scripts when invoking them
426via <code>npm run-script</code>.</p>
427<p>For example, myapp could have this:</p>
428<pre><code class="language-json">{
429  "bin": {
430    "myapp": "./cli.js"
431  }
432}
433</code></pre>
434<p>So, when you install myapp, in case of unix-like OS it'll create a symlink
435from the <code>cli.js</code> script to <code>/usr/local/bin/myapp</code> and in case of windows it
436will create a cmd file usually at <code>C:\Users\{Username}\AppData\Roaming\npm\myapp.cmd</code>
437which runs the <code>cli.js</code> script.</p>
438<p>If you have a single executable, and its name should be the name of the
439package, then you can just supply it as a string.  For example:</p>
440<pre><code class="language-json">{
441  "name": "my-program",
442  "version": "1.2.5",
443  "bin": "./path/to/program"
444}
445</code></pre>
446<p>would be the same as this:</p>
447<pre><code class="language-json">{
448  "name": "my-program",
449  "version": "1.2.5",
450  "bin": {
451    "my-program": "./path/to/program"
452  }
453}
454</code></pre>
455<p>Please make sure that your file(s) referenced in <code>bin</code> starts with
456<code>#!/usr/bin/env node</code>, otherwise the scripts are started without the node
457executable!</p>
458<p>Note that you can also set the executable files using <a href="#directoriesbin">directories.bin</a>.</p>
459<p>See <a href="../configuring-npm/folders#executables.html">folders</a> for more info on
460executables.</p>
461<h3 id="man">man</h3>
462<p>Specify either a single file or an array of filenames to put in place for
463the <code>man</code> program to find.</p>
464<p>If only a single file is provided, then it's installed such that it is the
465result from <code>man &lt;pkgname&gt;</code>, regardless of its actual filename.  For
466example:</p>
467<pre><code class="language-json">{
468  "name": "foo",
469  "version": "1.2.3",
470  "description": "A packaged foo fooer for fooing foos",
471  "main": "foo.js",
472  "man": "./man/doc.1"
473}
474</code></pre>
475<p>would link the <code>./man/doc.1</code> file in such that it is the target for <code>man foo</code></p>
476<p>If the filename doesn't start with the package name, then it's prefixed.
477So, this:</p>
478<pre><code class="language-json">{
479  "name": "foo",
480  "version": "1.2.3",
481  "description": "A packaged foo fooer for fooing foos",
482  "main": "foo.js",
483  "man": [
484    "./man/foo.1",
485    "./man/bar.1"
486  ]
487}
488</code></pre>
489<p>will create files to do <code>man foo</code> and <code>man foo-bar</code>.</p>
490<p>Man files must end with a number, and optionally a <code>.gz</code> suffix if they are
491compressed.  The number dictates which man section the file is installed
492into.</p>
493<pre><code class="language-json">{
494  "name": "foo",
495  "version": "1.2.3",
496  "description": "A packaged foo fooer for fooing foos",
497  "main": "foo.js",
498  "man": [
499    "./man/foo.1",
500    "./man/foo.2"
501  ]
502}
503</code></pre>
504<p>will create entries for <code>man foo</code> and <code>man 2 foo</code></p>
505<h3 id="directories">directories</h3>
506<p>The CommonJS <a href="http://wiki.commonjs.org/wiki/Packages/1.0">Packages</a> spec
507details a few ways that you can indicate the structure of your package
508using a <code>directories</code> object. If you look at <a href="https://registry.npmjs.org/npm/latest">npm's
509package.json</a>, you'll see that it
510has directories for doc, lib, and man.</p>
511<p>In the future, this information may be used in other creative ways.</p>
512<h4 id="directoriesbin">directories.bin</h4>
513<p>If you specify a <code>bin</code> directory in <code>directories.bin</code>, all the files in
514that folder will be added.</p>
515<p>Because of the way the <code>bin</code> directive works, specifying both a <code>bin</code> path
516and setting <code>directories.bin</code> is an error. If you want to specify
517individual files, use <code>bin</code>, and for all the files in an existing <code>bin</code>
518directory, use <code>directories.bin</code>.</p>
519<h4 id="directoriesman">directories.man</h4>
520<p>A folder that is full of man pages.  Sugar to generate a "man" array by
521walking the folder.</p>
522<h3 id="repository">repository</h3>
523<p>Specify the place where your code lives. This is helpful for people who
524want to contribute.  If the git repo is on GitHub, then the <code>npm docs</code>
525command will be able to find you.</p>
526<p>Do it like this:</p>
527<pre><code class="language-json">{
528  "repository": {
529    "type": "git",
530    "url": "https://github.com/npm/cli.git"
531  }
532}
533</code></pre>
534<p>The URL should be a publicly available (perhaps read-only) url that can be
535handed directly to a VCS program without any modification.  It should not
536be a url to an html project page that you put in your browser.  It's for
537computers.</p>
538<p>For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the
539same shortcut syntax you use for <code>npm install</code>:</p>
540<pre><code class="language-json">{
541  "repository": "npm/npm",
542
543  "repository": "github:user/repo",
544
545  "repository": "gist:11081aaa281",
546
547  "repository": "bitbucket:user/repo",
548
549  "repository": "gitlab:user/repo"
550}
551</code></pre>
552<p>If the <code>package.json</code> for your package is not in the root directory (for
553example if it is part of a monorepo), you can specify the directory in
554which it lives:</p>
555<pre><code class="language-json">{
556  "repository": {
557    "type": "git",
558    "url": "https://github.com/facebook/react.git",
559    "directory": "packages/react-dom"
560  }
561}
562</code></pre>
563<h3 id="scripts">scripts</h3>
564<p>The "scripts" property is a dictionary containing script commands that are
565run at various times in the lifecycle of your package.  The key is the
566lifecycle event, and the value is the command to run at that point.</p>
567<p>See <a href="../using-npm/scripts.html"><code>scripts</code></a> to find out more about writing package
568scripts.</p>
569<h3 id="config">config</h3>
570<p>A "config" object can be used to set configuration parameters used in
571package scripts that persist across upgrades.  For instance, if a package
572had the following:</p>
573<pre><code class="language-json">{
574  "name": "foo",
575  "config": {
576    "port": "8080"
577  }
578}
579</code></pre>
580<p>It could also have a "start" command that referenced the
581<code>npm_package_config_port</code> environment variable.</p>
582<h3 id="dependencies">dependencies</h3>
583<p>Dependencies are specified in a simple object that maps a package name to a
584version range. The version range is a string which has one or more
585space-separated descriptors.  Dependencies can also be identified with a
586tarball or git URL.</p>
587<p><strong>Please do not put test harnesses or transpilers or other "development"
588time tools in your <code>dependencies</code> object.</strong>  See <code>devDependencies</code>, below.</p>
589<p>See <a href="https://github.com/npm/node-semver#versions">semver</a> for more details about specifying version ranges.</p>
590<ul>
591<li><code>version</code> Must match <code>version</code> exactly</li>
592<li><code>&gt;version</code> Must be greater than <code>version</code></li>
593<li><code>&gt;=version</code> etc</li>
594<li><code>&lt;version</code></li>
595<li><code>&lt;=version</code></li>
596<li><code>~version</code> "Approximately equivalent to version"  See
597<a href="https://github.com/npm/node-semver#versions">semver</a></li>
598<li><code>^version</code> "Compatible with version"  See <a href="https://github.com/npm/node-semver#versions">semver</a></li>
599<li><code>1.2.x</code> 1.2.0, 1.2.1, etc., but not 1.3.0</li>
600<li><code>http://...</code> See 'URLs as Dependencies' below</li>
601<li><code>*</code> Matches any version</li>
602<li><code>""</code> (just an empty string) Same as <code>*</code></li>
603<li><code>version1 - version2</code> Same as <code>&gt;=version1 &lt;=version2</code>.</li>
604<li><code>range1 || range2</code> Passes if either range1 or range2 are satisfied.</li>
605<li><code>git...</code> See 'Git URLs as Dependencies' below</li>
606<li><code>user/repo</code> See 'GitHub URLs' below</li>
607<li><code>tag</code> A specific version tagged and published as <code>tag</code>  See <a href="../commands/npm-dist-tag.html"><code>npm dist-tag</code></a></li>
608<li><code>path/path/path</code> See <a href="#local-paths">Local Paths</a> below</li>
609</ul>
610<p>For example, these are all valid:</p>
611<pre><code class="language-json">{
612  "dependencies": {
613    "foo": "1.0.0 - 2.9999.9999",
614    "bar": "&gt;=1.0.2 &lt;2.1.2",
615    "baz": "&gt;1.0.2 &lt;=2.3.4",
616    "boo": "2.0.1",
617    "qux": "&lt;1.0.0 || &gt;=2.3.1 &lt;2.4.5 || &gt;=2.5.2 &lt;3.0.0",
618    "asd": "http://asdf.com/asdf.tar.gz",
619    "til": "~1.2",
620    "elf": "~1.2.3",
621    "two": "2.x",
622    "thr": "3.3.x",
623    "lat": "latest",
624    "dyl": "file:../dyl"
625  }
626}
627</code></pre>
628<h4 id="urls-as-dependencies">URLs as Dependencies</h4>
629<p>You may specify a tarball URL in place of a version range.</p>
630<p>This tarball will be downloaded and installed locally to your package at
631install time.</p>
632<h4 id="git-urls-as-dependencies">Git URLs as Dependencies</h4>
633<p>Git urls are of the form:</p>
634<pre><code class="language-bash">&lt;protocol&gt;://[&lt;user&gt;[:&lt;password&gt;]@]&lt;hostname&gt;[:&lt;port&gt;][:][/]&lt;path&gt;[#&lt;commit-ish&gt; | #semver:&lt;semver&gt;]
635</code></pre>
636<p><code>&lt;protocol&gt;</code> is one of <code>git</code>, <code>git+ssh</code>, <code>git+http</code>, <code>git+https</code>, or
637<code>git+file</code>.</p>
638<p>If <code>#&lt;commit-ish&gt;</code> is provided, it will be used to clone exactly that
639commit. If the commit-ish has the format <code>#semver:&lt;semver&gt;</code>, <code>&lt;semver&gt;</code> can
640be any valid semver range or exact version, and npm will look for any tags
641or refs matching that range in the remote repository, much as it would for
642a registry dependency. If neither <code>#&lt;commit-ish&gt;</code> or <code>#semver:&lt;semver&gt;</code> is
643specified, then the default branch is used.</p>
644<p>Examples:</p>
645<pre><code class="language-bash">git+ssh://git@github.com:npm/cli.git#v1.0.27
646git+ssh://git@github.com:npm/cli#semver:^5.0
647git+https://isaacs@github.com/npm/cli.git
648git://github.com/npm/cli.git#v1.0.27
649</code></pre>
650<p>When installing from a <code>git</code> repository, the presence of certain fields in the
651<code>package.json</code> will cause npm to believe it needs to perform a build. To do so
652your repository will be cloned into a temporary directory, all of its deps
653installed, relevant scripts run, and the resulting directory packed and
654installed.</p>
655<p>This flow will occur if your git dependency uses <code>workspaces</code>, or if any of the
656following scripts are present:</p>
657<ul>
658<li><code>build</code></li>
659<li><code>prepare</code></li>
660<li><code>prepack</code></li>
661<li><code>preinstall</code></li>
662<li><code>install</code></li>
663<li><code>postinstall</code></li>
664</ul>
665<p>If your git repository includes pre-built artifacts, you will likely want to
666make sure that none of the above scripts are defined, or your dependency
667will be rebuilt for every installation.</p>
668<h4 id="github-urls">GitHub URLs</h4>
669<p>As of version 1.1.65, you can refer to GitHub urls as just "foo":
670"user/foo-project".  Just as with git URLs, a <code>commit-ish</code> suffix can be
671included.  For example:</p>
672<pre><code class="language-json">{
673  "name": "foo",
674  "version": "0.0.0",
675  "dependencies": {
676    "express": "expressjs/express",
677    "mocha": "mochajs/mocha#4727d357ea",
678    "module": "user/repo#feature\/branch"
679  }
680}
681</code></pre>
682<h4 id="local-paths">Local Paths</h4>
683<p>As of version 2.0.0 you can provide a path to a local directory that
684contains a package. Local paths can be saved using <code>npm install -S</code> or <code>npm install --save</code>, using any of these forms:</p>
685<pre><code class="language-bash">../foo/bar
686~/foo/bar
687./foo/bar
688/foo/bar
689</code></pre>
690<p>in which case they will be normalized to a relative path and added to your
691<code>package.json</code>. For example:</p>
692<pre><code class="language-json">{
693  "name": "baz",
694  "dependencies": {
695    "bar": "file:../foo/bar"
696  }
697}
698</code></pre>
699<p>This feature is helpful for local offline development and creating tests
700that require npm installing where you don't want to hit an external server,
701but should not be used when publishing your package to the public registry.</p>
702<p><em>note</em>: Packages linked by local path will not have their own
703dependencies installed when <code>npm install</code> is ran in this case.  You must
704run <code>npm install</code> from inside the local path itself.</p>
705<h3 id="devdependencies">devDependencies</h3>
706<p>If someone is planning on downloading and using your module in their
707program, then they probably don't want or need to download and build the
708external test or documentation framework that you use.</p>
709<p>In this case, it's best to map these additional items in a
710<code>devDependencies</code> object.</p>
711<p>These things will be installed when doing <code>npm link</code> or <code>npm install</code> from
712the root of a package, and can be managed like any other npm configuration
713param.  See <a href="../using-npm/config.html"><code>config</code></a> for more on the topic.</p>
714<p>For build steps that are not platform-specific, such as compiling
715CoffeeScript or other languages to JavaScript, use the <code>prepare</code> script to
716do this, and make the required package a devDependency.</p>
717<p>For example:</p>
718<pre><code class="language-json">{
719  "name": "ethopia-waza",
720  "description": "a delightfully fruity coffee varietal",
721  "version": "1.2.3",
722  "devDependencies": {
723    "coffee-script": "~1.6.3"
724  },
725  "scripts": {
726    "prepare": "coffee -o lib/ -c src/waza.coffee"
727  },
728  "main": "lib/waza.js"
729}
730</code></pre>
731<p>The <code>prepare</code> script will be run before publishing, so that users can
732consume the functionality without requiring them to compile it themselves.
733In dev mode (ie, locally running <code>npm install</code>), it'll run this script as
734well, so that you can test it easily.</p>
735<h3 id="peerdependencies">peerDependencies</h3>
736<p>In some cases, you want to express the compatibility of your package with a
737host tool or library, while not necessarily doing a <code>require</code> of this host.
738This is usually referred to as a <em>plugin</em>. Notably, your module may be
739exposing a specific interface, expected and specified by the host
740documentation.</p>
741<p>For example:</p>
742<pre><code class="language-json">{
743  "name": "tea-latte",
744  "version": "1.3.5",
745  "peerDependencies": {
746    "tea": "2.x"
747  }
748}
749</code></pre>
750<p>This ensures your package <code>tea-latte</code> can be installed <em>along</em> with the
751second major version of the host package <code>tea</code> only. <code>npm install tea-latte</code> could possibly yield the following dependency graph:</p>
752<pre><code class="language-bash">├── tea-latte@1.3.5
753└── tea@2.2.0
754</code></pre>
755<p>In npm versions 3 through 6, <code>peerDependencies</code> were not automatically
756installed, and would raise a warning if an invalid version of the peer
757dependency was found in the tree.  As of npm v7, peerDependencies <em>are</em>
758installed by default.</p>
759<p>Trying to install another plugin with a conflicting requirement may cause
760an error if the tree cannot be resolved correctly. For this reason, make
761sure your plugin requirement is as broad as possible, and not to lock it
762down to specific patch versions.</p>
763<p>Assuming the host complies with <a href="https://semver.org/">semver</a>, only changes
764in the host package's major version will break your plugin. Thus, if you've
765worked with every 1.x version of the host package, use <code>"^1.0"</code> or <code>"1.x"</code>
766to express this. If you depend on features introduced in 1.5.2, use
767<code>"^1.5.2"</code>.</p>
768<h3 id="peerdependenciesmeta">peerDependenciesMeta</h3>
769<p>When a user installs your package, npm will emit warnings if packages
770specified in <code>peerDependencies</code> are not already installed. The
771<code>peerDependenciesMeta</code> field serves to provide npm more information on how
772your peer dependencies are to be used. Specifically, it allows peer
773dependencies to be marked as optional.</p>
774<p>For example:</p>
775<pre><code class="language-json">{
776  "name": "tea-latte",
777  "version": "1.3.5",
778  "peerDependencies": {
779    "tea": "2.x",
780    "soy-milk": "1.2"
781  },
782  "peerDependenciesMeta": {
783    "soy-milk": {
784      "optional": true
785    }
786  }
787}
788</code></pre>
789<p>Marking a peer dependency as optional ensures npm will not emit a warning
790if the <code>soy-milk</code> package is not installed on the host. This allows you to
791integrate and interact with a variety of host packages without requiring
792all of them to be installed.</p>
793<h3 id="bundledependencies">bundleDependencies</h3>
794<p>This defines an array of package names that will be bundled when publishing
795the package.</p>
796<p>In cases where you need to preserve npm packages locally or have them
797available through a single file download, you can bundle the packages in a
798tarball file by specifying the package names in the <code>bundleDependencies</code>
799array and executing <code>npm pack</code>.</p>
800<p>For example:</p>
801<p>If we define a package.json like this:</p>
802<pre><code class="language-json">{
803  "name": "awesome-web-framework",
804  "version": "1.0.0",
805  "bundleDependencies": [
806    "renderized",
807    "super-streams"
808  ]
809}
810</code></pre>
811<p>we can obtain <code>awesome-web-framework-1.0.0.tgz</code> file by running <code>npm pack</code>.
812This file contains the dependencies <code>renderized</code> and <code>super-streams</code> which
813can be installed in a new project by executing <code>npm install awesome-web-framework-1.0.0.tgz</code>.  Note that the package names do not
814include any versions, as that information is specified in <code>dependencies</code>.</p>
815<p>If this is spelled <code>"bundledDependencies"</code>, then that is also honored.</p>
816<p>Alternatively, <code>"bundleDependencies"</code> can be defined as a boolean value. A
817value of <code>true</code> will bundle all dependencies, a value of <code>false</code> will bundle
818none.</p>
819<h3 id="optionaldependencies">optionalDependencies</h3>
820<p>If a dependency can be used, but you would like npm to proceed if it cannot
821be found or fails to install, then you may put it in the
822<code>optionalDependencies</code> object.  This is a map of package name to version or
823url, just like the <code>dependencies</code> object.  The difference is that build
824failures do not cause installation to fail.  Running <code>npm install --omit=optional</code> will prevent these dependencies from being installed.</p>
825<p>It is still your program's responsibility to handle the lack of the
826dependency.  For example, something like this:</p>
827<pre><code class="language-js">try {
828  var foo = require('foo')
829  var fooVersion = require('foo/package.json').version
830} catch (er) {
831  foo = null
832}
833if ( notGoodFooVersion(fooVersion) ) {
834  foo = null
835}
836
837// .. then later in your program ..
838
839if (foo) {
840  foo.doFooThings()
841}
842</code></pre>
843<p>Entries in <code>optionalDependencies</code> will override entries of the same name in
844<code>dependencies</code>, so it's usually best to only put in one place.</p>
845<h3 id="overrides">overrides</h3>
846<p>If you need to make specific changes to dependencies of your dependencies, for
847example replacing the version of a dependency with a known security issue,
848replacing an existing dependency with a fork, or making sure that the same
849version of a package is used everywhere, then you may add an override.</p>
850<p>Overrides provide a way to replace a package in your dependency tree with
851another version, or another package entirely. These changes can be scoped as
852specific or as vague as desired.</p>
853<p>To make sure the package <code>foo</code> is always installed as version <code>1.0.0</code> no matter
854what version your dependencies rely on:</p>
855<pre><code class="language-json">{
856  "overrides": {
857    "foo": "1.0.0"
858  }
859}
860</code></pre>
861<p>The above is a short hand notation, the full object form can be used to allow
862overriding a package itself as well as a child of the package. This will cause
863<code>foo</code> to always be <code>1.0.0</code> while also making <code>bar</code> at any depth beyond <code>foo</code>
864also <code>1.0.0</code>:</p>
865<pre><code class="language-json">{
866  "overrides": {
867    "foo": {
868      ".": "1.0.0",
869      "bar": "1.0.0"
870    }
871  }
872}
873</code></pre>
874<p>To only override <code>foo</code> to be <code>1.0.0</code> when it's a child (or grandchild, or great
875grandchild, etc) of the package <code>bar</code>:</p>
876<pre><code class="language-json">{
877  "overrides": {
878    "bar": {
879      "foo": "1.0.0"
880    }
881  }
882}
883</code></pre>
884<p>Keys can be nested to any arbitrary length. To override <code>foo</code> only when it's a
885child of <code>bar</code> and only when <code>bar</code> is a child of <code>baz</code>:</p>
886<pre><code class="language-json">{
887  "overrides": {
888    "baz": {
889      "bar": {
890        "foo": "1.0.0"
891      }
892    }
893  }
894}
895</code></pre>
896<p>The key of an override can also include a version, or range of versions.
897To override <code>foo</code> to <code>1.0.0</code>, but only when it's a child of <code>bar@2.0.0</code>:</p>
898<pre><code class="language-json">{
899  "overrides": {
900    "bar@2.0.0": {
901      "foo": "1.0.0"
902    }
903  }
904}
905</code></pre>
906<p>You may not set an override for a package that you directly depend on unless
907both the dependency and the override itself share the exact same spec. To make
908this limitation easier to deal with, overrides may also be defined as a
909reference to a spec for a direct dependency by prefixing the name of the
910package you wish the version to match with a <code>$</code>.</p>
911<pre><code class="language-json">{
912  "dependencies": {
913    "foo": "^1.0.0"
914  },
915  "overrides": {
916    // BAD, will throw an EOVERRIDE error
917    // "foo": "^2.0.0"
918    // GOOD, specs match so override is allowed
919    // "foo": "^1.0.0"
920    // BEST, the override is defined as a reference to the dependency
921    "foo": "$foo",
922    // the referenced package does not need to match the overridden one
923    "bar": "$foo"
924  }
925}
926</code></pre>
927<h3 id="engines">engines</h3>
928<p>You can specify the version of node that your stuff works on:</p>
929<pre><code class="language-json">{
930  "engines": {
931    "node": "&gt;=0.10.3 &lt;15"
932  }
933}
934</code></pre>
935<p>And, like with dependencies, if you don't specify the version (or if you
936specify "*" as the version), then any version of node will do.</p>
937<p>You can also use the "engines" field to specify which versions of npm are
938capable of properly installing your program.  For example:</p>
939<pre><code class="language-json">{
940  "engines": {
941    "npm": "~1.0.20"
942  }
943}
944</code></pre>
945<p>Unless the user has set the
946<a href="../using-npm/config#engine-strict.html"><code>engine-strict</code> config</a> flag, this field is
947advisory only and will only produce warnings when your package is installed as a
948dependency.</p>
949<h3 id="os">os</h3>
950<p>You can specify which operating systems your
951module will run on:</p>
952<pre><code class="language-json">{
953  "os": [
954    "darwin",
955    "linux"
956  ]
957}
958</code></pre>
959<p>You can also block instead of allowing operating systems, just prepend the
960blocked os with a '!':</p>
961<pre><code class="language-json">{
962  "os": [
963    "!win32"
964  ]
965}
966</code></pre>
967<p>The host operating system is determined by <code>process.platform</code></p>
968<p>It is allowed to both block and allow an item, although there isn't any
969good reason to do this.</p>
970<h3 id="cpu">cpu</h3>
971<p>If your code only runs on certain cpu architectures,
972you can specify which ones.</p>
973<pre><code class="language-json">{
974  "cpu": [
975    "x64",
976    "ia32"
977  ]
978}
979</code></pre>
980<p>Like the <code>os</code> option, you can also block architectures:</p>
981<pre><code class="language-json">{
982  "cpu": [
983    "!arm",
984    "!mips"
985  ]
986}
987</code></pre>
988<p>The host architecture is determined by <code>process.arch</code></p>
989<h3 id="private">private</h3>
990<p>If you set <code>"private": true</code> in your package.json, then npm will refuse to
991publish it.</p>
992<p>This is a way to prevent accidental publication of private repositories.
993If you would like to ensure that a given package is only ever published to
994a specific registry (for example, an internal registry), then use the
995<code>publishConfig</code> dictionary described below to override the <code>registry</code>
996config param at publish-time.</p>
997<h3 id="publishconfig">publishConfig</h3>
998<p>This is a set of config values that will be used at publish-time. It's
999especially handy if you want to set the tag, registry or access, so that
1000you can ensure that a given package is not tagged with "latest", published
1001to the global public registry or that a scoped module is private by
1002default.</p>
1003<p>See <a href="../using-npm/config.html"><code>config</code></a> to see the list of config options that
1004can be overridden.</p>
1005<h3 id="workspaces">workspaces</h3>
1006<p>The optional <code>workspaces</code> field is an array of file patterns that describes
1007locations within the local file system that the install client should look
1008up to find each <a href="../using-npm/workspaces.html">workspace</a> that needs to be
1009symlinked to the top level <code>node_modules</code> folder.</p>
1010<p>It can describe either the direct paths of the folders to be used as
1011workspaces or it can define globs that will resolve to these same folders.</p>
1012<p>In the following example, all folders located inside the folder
1013<code>./packages</code> will be treated as workspaces as long as they have valid
1014<code>package.json</code> files inside them:</p>
1015<pre><code class="language-json">{
1016  "name": "workspace-example",
1017  "workspaces": [
1018    "./packages/*"
1019  ]
1020}
1021</code></pre>
1022<p>See <a href="../using-npm/workspaces.html"><code>workspaces</code></a> for more examples.</p>
1023<h3 id="default-values">DEFAULT VALUES</h3>
1024<p>npm will default some values based on package contents.</p>
1025<ul>
1026<li>
1027<p><code>"scripts": {"start": "node server.js"}</code></p>
1028<p>If there is a <code>server.js</code> file in the root of your package, then npm will
1029default the <code>start</code> command to <code>node server.js</code>.</p>
1030</li>
1031<li>
1032<p><code>"scripts":{"install": "node-gyp rebuild"}</code></p>
1033<p>If there is a <code>binding.gyp</code> file in the root of your package and you have
1034not defined an <code>install</code> or <code>preinstall</code> script, npm will default the
1035<code>install</code> command to compile using node-gyp.</p>
1036</li>
1037<li>
1038<p><code>"contributors": [...]</code></p>
1039<p>If there is an <code>AUTHORS</code> file in the root of your package, npm will treat
1040each line as a <code>Name &lt;email&gt; (url)</code> format, where email and url are
1041optional.  Lines which start with a <code>#</code> or are blank, will be ignored.</p>
1042</li>
1043</ul>
1044<h3 id="see-also">SEE ALSO</h3>
1045<ul>
1046<li><a href="https://github.com/npm/node-semver#versions">semver</a></li>
1047<li><a href="../using-npm/workspaces.html">workspaces</a></li>
1048<li><a href="../commands/npm-init.html">npm init</a></li>
1049<li><a href="../commands/npm-version.html">npm version</a></li>
1050<li><a href="../commands/npm-config.html">npm config</a></li>
1051<li><a href="../commands/npm-help.html">npm help</a></li>
1052<li><a href="../commands/npm-install.html">npm install</a></li>
1053<li><a href="../commands/npm-publish.html">npm publish</a></li>
1054<li><a href="../commands/npm-uninstall.html">npm uninstall</a></li>
1055</ul></div>
1056
1057<footer id="edit">
1058<a href="https://github.com/npm/cli/edit/latest/docs/content/configuring-npm/package-json.md">
1059<svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
1060<path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
1061</svg>
1062Edit this page on GitHub
1063</a>
1064</footer>
1065</section>
1066
1067
1068
1069</body></html>