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