npmrc.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <!DOCTYPE html><html><head>
  2. <meta charset="utf-8">
  3. <title>.npmrc</title>
  4. <style>
  5. body {
  6. background-color: #ffffff;
  7. color: #24292e;
  8. margin: 0;
  9. line-height: 1.5;
  10. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  11. }
  12. #rainbar {
  13. height: 10px;
  14. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  15. }
  16. a {
  17. text-decoration: none;
  18. color: #0366d6;
  19. }
  20. a:hover {
  21. text-decoration: underline;
  22. }
  23. pre {
  24. margin: 1em 0px;
  25. padding: 1em;
  26. border: solid 1px #e1e4e8;
  27. border-radius: 6px;
  28. display: block;
  29. overflow: auto;
  30. white-space: pre;
  31. background-color: #f6f8fa;
  32. color: #393a34;
  33. }
  34. code {
  35. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  36. font-size: 85%;
  37. padding: 0.2em 0.4em;
  38. background-color: #f6f8fa;
  39. color: #393a34;
  40. }
  41. pre > code {
  42. padding: 0;
  43. background-color: inherit;
  44. color: inherit;
  45. }
  46. h1, h2, h3 {
  47. font-weight: 600;
  48. }
  49. #logobar {
  50. background-color: #333333;
  51. margin: 0 auto;
  52. padding: 1em 4em;
  53. }
  54. #logobar .logo {
  55. float: left;
  56. }
  57. #logobar .title {
  58. font-weight: 600;
  59. color: #dddddd;
  60. float: left;
  61. margin: 5px 0 0 1em;
  62. }
  63. #logobar:after {
  64. content: "";
  65. display: block;
  66. clear: both;
  67. }
  68. #content {
  69. margin: 0 auto;
  70. padding: 0 4em;
  71. }
  72. #table_of_contents > h2 {
  73. font-size: 1.17em;
  74. }
  75. #table_of_contents ul:first-child {
  76. border: solid 1px #e1e4e8;
  77. border-radius: 6px;
  78. padding: 1em;
  79. background-color: #f6f8fa;
  80. color: #393a34;
  81. }
  82. #table_of_contents ul {
  83. list-style-type: none;
  84. padding-left: 1.5em;
  85. }
  86. #table_of_contents li {
  87. font-size: 0.9em;
  88. }
  89. #table_of_contents li a {
  90. color: #000000;
  91. }
  92. header.title {
  93. border-bottom: solid 1px #e1e4e8;
  94. }
  95. header.title > h1 {
  96. margin-bottom: 0.25em;
  97. }
  98. header.title > .description {
  99. display: block;
  100. margin-bottom: 0.5em;
  101. line-height: 1;
  102. }
  103. header.title .version {
  104. font-size: 0.8em;
  105. color: #666666;
  106. }
  107. footer#edit {
  108. border-top: solid 1px #e1e4e8;
  109. margin: 3em 0 4em 0;
  110. padding-top: 2em;
  111. }
  112. table {
  113. width: 100%;
  114. margin: 1em 0;
  115. border-radius: 6px;
  116. border: 1px solid #e1e4e8;
  117. overflow: hidden;
  118. border-collapse: separate;
  119. border-spacing: 0;
  120. }
  121. table thead {
  122. background-color: #f6f8fa;
  123. }
  124. table tbody {
  125. background-color: #ffffff;
  126. }
  127. table th,
  128. table td {
  129. padding: 0.75em;
  130. text-align: left;
  131. border-right: 1px solid #e1e4e8;
  132. border-bottom: 1px solid #e1e4e8;
  133. }
  134. table th:last-child,
  135. table td:last-child {
  136. border-right: none;
  137. }
  138. table tbody tr:last-child td {
  139. border-bottom: none;
  140. }
  141. table th {
  142. font-weight: 600;
  143. background-color: #f6f8fa;
  144. }
  145. table code {
  146. white-space: nowrap;
  147. }
  148. </style>
  149. </head>
  150. <body>
  151. <div id="banner">
  152. <div id="rainbar"></div>
  153. <div id="logobar">
  154. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  155. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  156. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  157. </svg>
  158. <div class="title">
  159. npm command-line interface
  160. </div>
  161. </div>
  162. </div>
  163. <section id="content">
  164. <header class="title">
  165. <h1 id="----npmrc----11120">
  166. <span>.npmrc</span>
  167. <span class="version">@11.12.0</span>
  168. </h1>
  169. <span class="description">The npm config files</span>
  170. </header>
  171. <section id="table_of_contents">
  172. <h2 id="table-of-contents">Table of contents</h2>
  173. <div id="_table_of_contents"><ul><li><a href="#description">Description</a></li><li><a href="#files">Files</a></li><ul><li><a href="#comments">Comments</a></li><li><a href="#per-project-config-file">Per-project config file</a></li><li><a href="#per-user-config-file">Per-user config file</a></li><li><a href="#global-config-file">Global config file</a></li><li><a href="#built-in-config-file">Built-in config file</a></li></ul><li><a href="#auth-related-configuration">Auth related configuration</a></li><li><a href="#unsupported-custom-configuration-keys">Unsupported Custom Configuration Keys</a></li><li><a href="#custom--third-party-config-keys">Custom / third-party config keys</a></li><li><a href="#see-also">See also</a></li></ul></div>
  174. </section>
  175. <div id="_content"><h3 id="description">Description</h3>
  176. <p>npm gets its config settings from the command line, environment variables, and <code>npmrc</code> files.</p>
  177. <p>The <code>npm config</code> command can be used to update and edit the contents of the user and global npmrc files.</p>
  178. <p>For a list of available configuration options, see <a href="../using-npm/config.html">config</a>.</p>
  179. <h3 id="files">Files</h3>
  180. <p>The four relevant files are:</p>
  181. <ul>
  182. <li>per-project config file (<code>/path/to/my/project/.npmrc</code>)</li>
  183. <li>per-user config file (<code>~/.npmrc</code>)</li>
  184. <li>global config file (<code>$PREFIX/etc/npmrc</code>)</li>
  185. <li>npm builtin config file (<code>/path/to/npm/npmrc</code>)</li>
  186. </ul>
  187. <p>All npm config files are an ini-formatted list of <code>key = value</code> parameters.
  188. Environment variables can be replaced using <code>${VARIABLE_NAME}</code>.
  189. By default if the variable is not defined, it is left unreplaced.
  190. By adding <code>?</code> after variable name they can be forced to evaluate to an empty string instead.
  191. For example:</p>
  192. <pre><code class="language-bash">cache = ${HOME}/.npm-packages
  193. node-options = "${NODE_OPTIONS?} --use-system-ca"
  194. </code></pre>
  195. <p>Each of these files is loaded, and config options are resolved in priority order.
  196. For example, a setting in the userconfig file would override the setting in the globalconfig file.</p>
  197. <p>Array values are specified by adding "[]" after the key name.
  198. For example:</p>
  199. <pre><code class="language-bash">key[] = "first value"
  200. key[] = "second value"
  201. </code></pre>
  202. <h4 id="comments">Comments</h4>
  203. <p>Lines in <code>.npmrc</code> files are interpreted as comments when they begin with a
  204. <code>;</code> or <code>#</code> character.
  205. <code>.npmrc</code> files are parsed by
  206. <a href="https://github.com/npm/ini">npm/ini</a>, which specifies this comment syntax.</p>
  207. <p>For example:</p>
  208. <pre><code class="language-bash"># last modified: 01 Jan 2016
  209. ; Set a new registry for a scoped package
  210. @myscope:registry=https://mycustomregistry.example.org
  211. </code></pre>
  212. <h4 id="per-project-config-file">Per-project config file</h4>
  213. <p>When working locally in a project, a <code>.npmrc</code> file in the root of the project (ie, a sibling of <code>node_modules</code> and <code>package.json</code>) will set config values specific to this project.</p>
  214. <p>Note that this only applies to the root of the project that you're running npm in.
  215. It has no effect when your module is published.
  216. For example, you can't publish a module that forces itself to install globally, or in a different location.</p>
  217. <p>Additionally, this file is not read in global mode, such as when running <code>npm install -g</code>.</p>
  218. <h4 id="per-user-config-file">Per-user config file</h4>
  219. <p><code>$HOME/.npmrc</code> (or the <code>userconfig</code> param, if set in the environment or on the command line)</p>
  220. <h4 id="global-config-file">Global config file</h4>
  221. <p><code>$PREFIX/etc/npmrc</code> (or the <code>globalconfig</code> param, if set above): This file is an ini-file formatted list of <code>key = value</code> parameters.
  222. Environment variables can be replaced as above.</p>
  223. <h4 id="built-in-config-file">Built-in config file</h4>
  224. <p><code>path/to/npm/itself/npmrc</code></p>
  225. <p>This is an unchangeable "builtin" configuration file that npm keeps consistent across updates.
  226. Set fields in here using the <code>./configure</code> script that comes with npm.
  227. This is primarily for distribution maintainers to override default configs in a standard and consistent manner.</p>
  228. <h3 id="auth-related-configuration">Auth related configuration</h3>
  229. <p>The settings <code>_auth</code>, <code>_authToken</code>, <code>username</code>, <code>_password</code>, <code>certfile</code>, and <code>keyfile</code> must all be scoped to a specific registry.
  230. This ensures that <code>npm</code> will never send credentials to the wrong host.</p>
  231. <p>The full list is:</p>
  232. <ul>
  233. <li><code>_auth</code> (base64 authentication string)</li>
  234. <li><code>_authToken</code> (authentication token)</li>
  235. <li><code>username</code></li>
  236. <li><code>_password</code></li>
  237. <li><code>email</code></li>
  238. <li><code>cafile</code> (path to certificate authority file)</li>
  239. <li><code>certfile</code> (path to certificate file)</li>
  240. <li><code>keyfile</code> (path to key file)</li>
  241. </ul>
  242. <p>In order to scope these values, they must be prefixed by a URI fragment.
  243. If the credential is meant for any request to a registry on a single host, the scope may look like <code>//registry.npmjs.org/:</code>.
  244. If it must be scoped to a specific path on the host that path may also be provided, such as
  245. <code>//my-custom-registry.org/unique/path:</code>.</p>
  246. <h3 id="unsupported-custom-configuration-keys">Unsupported Custom Configuration Keys</h3>
  247. <p>Starting in npm v11.2.0, npm warns when unknown configuration keys are defined in <code>.npmrc</code>. In a future major version of npm, these unknown keys may no longer be accepted.</p>
  248. <p>Only configuration keys that npm officially supports are recognized. Custom keys intended for third-party tools (for example, <code>electron-builder</code>) should not be placed in <code>.npmrc</code>.</p>
  249. <p>If you need package-level configuration for use in scripts, use the <code>config</code> field in your <code>package.json</code> instead:</p>
  250. <pre><code class="language-json">{
  251. "name": "my-package",
  252. "config": {
  253. "mirror": "https://example.com/"
  254. }
  255. }
  256. </code></pre>
  257. <p>Values defined in <code>package.json#config</code> are exposed to scripts as environment variables prefixed with <code>npm_package_config_</code>. For example:</p>
  258. <pre><code>npm_package_config_mirror
  259. </code></pre>
  260. <p>If you need to pass arguments to a script command, use <code>--</code> to separate npm arguments from script arguments:</p>
  261. <pre><code>npm run build -- --customFlag
  262. </code></pre>
  263. <p>Using environment variables is also recommended for cross-platform configuration instead of defining unsupported keys in <code>.npmrc</code>.</p>
  264. <pre><code>; bad config
  265. _authToken=MYTOKEN
  266. ; good config
  267. @myorg:registry=https://somewhere-else.com/myorg
  268. @another:registry=https://somewhere-else.com/another
  269. //registry.npmjs.org/:_authToken=MYTOKEN
  270. ; would apply to both @myorg and @another
  271. //somewhere-else.com/:_authToken=MYTOKEN
  272. ; would apply only to @myorg
  273. //somewhere-else.com/myorg/:_authToken=MYTOKEN1
  274. ; would apply only to @another
  275. //somewhere-else.com/another/:_authToken=MYTOKEN2
  276. </code></pre>
  277. <h3 id="custom--third-party-config-keys">Custom / third-party config keys</h3>
  278. <p>npm only recognizes its own <a href="../using-npm/config.html">configuration options</a>.
  279. If your <code>.npmrc</code> contains keys that are not part of npm's config definitions
  280. (for example, <code>electron_mirror</code> or <code>sass_binary_site</code>), npm will emit a
  281. warning:</p>
  282. <pre><code>warn Unknown user config "electron_mirror".
  283. This will stop working in the next major version of npm.
  284. </code></pre>
  285. <p>These keys were historically tolerated but are not officially supported.
  286. A future major version of npm will treat unknown top-level keys as errors.</p>
  287. <p>Some tools (such as <code>@electron/get</code> or <code>node-sass</code>) read their own
  288. configuration from environment variables or from <code>.npmrc</code> by convention.
  289. You can set these values as environment variables instead:</p>
  290. <pre><code class="language-bash">export ELECTRON_MIRROR="https://mirrorexample.npmjs.org/mirrors/electron/"
  291. export ELECTRON_CUSTOM_DIR="{{ version }}"
  292. </code></pre>
  293. <p>Environment variables are the most portable approach and work regardless
  294. of <code>.npmrc</code> format.</p>
  295. <h3 id="see-also">See also</h3>
  296. <ul>
  297. <li><a href="../configuring-npm/folders.html">npm folders</a></li>
  298. <li><a href="../commands/npm-config.html">npm config</a></li>
  299. <li><a href="../using-npm/config.html">config</a></li>
  300. <li><a href="../configuring-npm/package-json.html">package.json</a></li>
  301. <li><a href="../commands/npm.html">npm</a></li>
  302. </ul></div>
  303. <footer id="edit">
  304. <a href="https://github.com/npm/cli/edit/latest/docs/lib/content/configuring-npm/npmrc.md">
  305. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  306. <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>
  307. </svg>
  308. Edit this page on GitHub
  309. </a>
  310. </footer>
  311. </section>
  312. </body></html>