package-json.html 39 KB

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