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