package-json.5 30 KB

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