npmrc.5 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. .TH ".NPMRC" "5" "March 2026" "NPM@11.12.0" ""
  2. .SH "NAME"
  3. \fB.npmrc\fR - The npm config files
  4. .SS "Description"
  5. .P
  6. npm gets its config settings from the command line, environment variables, and \fBnpmrc\fR files.
  7. .P
  8. The \fBnpm config\fR command can be used to update and edit the contents of the user and global npmrc files.
  9. .P
  10. For a list of available configuration options, see npm help config.
  11. .SS "Files"
  12. .P
  13. The four relevant files are:
  14. .RS 0
  15. .IP \(bu 4
  16. per-project config file (\fB/path/to/my/project/.npmrc\fR)
  17. .IP \(bu 4
  18. per-user config file (\fB~/.npmrc\fR)
  19. .IP \(bu 4
  20. global config file (\fB$PREFIX/etc/npmrc\fR)
  21. .IP \(bu 4
  22. npm builtin config file (\fB/path/to/npm/npmrc\fR)
  23. .RE 0
  24. .P
  25. All npm config files are an ini-formatted list of \fBkey = value\fR parameters. Environment variables can be replaced using \fB${VARIABLE_NAME}\fR. By default if the variable is not defined, it is left unreplaced. By adding \fB?\fR after variable name they can be forced to evaluate to an empty string instead. For example:
  26. .P
  27. .RS 2
  28. .nf
  29. cache = ${HOME}/.npm-packages
  30. node-options = "${NODE_OPTIONS?} --use-system-ca"
  31. .fi
  32. .RE
  33. .P
  34. Each of these files is loaded, and config options are resolved in priority order. For example, a setting in the userconfig file would override the setting in the globalconfig file.
  35. .P
  36. Array values are specified by adding "\[lB]\[rB]" after the key name. For example:
  37. .P
  38. .RS 2
  39. .nf
  40. key\[lB]\[rB] = "first value"
  41. key\[lB]\[rB] = "second value"
  42. .fi
  43. .RE
  44. .SS "Comments"
  45. .P
  46. Lines in \fB.npmrc\fR files are interpreted as comments when they begin with a \fB;\fR or \fB#\fR character. \fB.npmrc\fR files are parsed by \fBnpm/ini\fR \fI\(lahttps://github.com/npm/ini\(ra\fR, which specifies this comment syntax.
  47. .P
  48. For example:
  49. .P
  50. .RS 2
  51. .nf
  52. # last modified: 01 Jan 2016
  53. ; Set a new registry for a scoped package
  54. @myscope:registry=https://mycustomregistry.example.org
  55. .fi
  56. .RE
  57. .SS "Per-project config file"
  58. .P
  59. When working locally in a project, a \fB.npmrc\fR file in the root of the project (ie, a sibling of \fBnode_modules\fR and \fBpackage.json\fR) will set config values specific to this project.
  60. .P
  61. Note that this only applies to the root of the project that you're running npm in. It has no effect when your module is published. For example, you can't publish a module that forces itself to install globally, or in a different location.
  62. .P
  63. Additionally, this file is not read in global mode, such as when running \fBnpm install -g\fR.
  64. .SS "Per-user config file"
  65. .P
  66. \fB$HOME/.npmrc\fR (or the \fBuserconfig\fR param, if set in the environment or on the command line)
  67. .SS "Global config file"
  68. .P
  69. \fB$PREFIX/etc/npmrc\fR (or the \fBglobalconfig\fR param, if set above): This file is an ini-file formatted list of \fBkey = value\fR parameters. Environment variables can be replaced as above.
  70. .SS "Built-in config file"
  71. .P
  72. \fBpath/to/npm/itself/npmrc\fR
  73. .P
  74. This is an unchangeable "builtin" configuration file that npm keeps consistent across updates. Set fields in here using the \fB./configure\fR script that comes with npm. This is primarily for distribution maintainers to override default configs in a standard and consistent manner.
  75. .SS "Auth related configuration"
  76. .P
  77. The settings \fB_auth\fR, \fB_authToken\fR, \fBusername\fR, \fB_password\fR, \fBcertfile\fR, and \fBkeyfile\fR must all be scoped to a specific registry. This ensures that \fBnpm\fR will never send credentials to the wrong host.
  78. .P
  79. The full list is:
  80. .RS 0
  81. .IP \(bu 4
  82. \fB_auth\fR (base64 authentication string)
  83. .IP \(bu 4
  84. \fB_authToken\fR (authentication token)
  85. .IP \(bu 4
  86. \fBusername\fR
  87. .IP \(bu 4
  88. \fB_password\fR
  89. .IP \(bu 4
  90. \fBemail\fR
  91. .IP \(bu 4
  92. \fBcafile\fR (path to certificate authority file)
  93. .IP \(bu 4
  94. \fBcertfile\fR (path to certificate file)
  95. .IP \(bu 4
  96. \fBkeyfile\fR (path to key file)
  97. .RE 0
  98. .P
  99. In order to scope these values, they must be prefixed by a URI fragment. If the credential is meant for any request to a registry on a single host, the scope may look like \fB//registry.npmjs.org/:\fR. If it must be scoped to a specific path on the host that path may also be provided, such as \fB//my-custom-registry.org/unique/path:\fR.
  100. .SS "Unsupported Custom Configuration Keys"
  101. .P
  102. Starting in npm v11.2.0, npm warns when unknown configuration keys are defined in \fB.npmrc\fR. In a future major version of npm, these unknown keys may no longer be accepted.
  103. .P
  104. Only configuration keys that npm officially supports are recognized. Custom keys intended for third-party tools (for example, \fBelectron-builder\fR) should not be placed in \fB.npmrc\fR.
  105. .P
  106. If you need package-level configuration for use in scripts, use the \fBconfig\fR field in your \fBpackage.json\fR instead:
  107. .P
  108. .RS 2
  109. .nf
  110. {
  111. "name": "my-package",
  112. "config": {
  113. "mirror": "https://example.com/"
  114. }
  115. }
  116. .fi
  117. .RE
  118. .P
  119. Values defined in \fBpackage.json#config\fR are exposed to scripts as environment variables prefixed with \fBnpm_package_config_\fR. For example:
  120. .P
  121. .RS 2
  122. .nf
  123. npm_package_config_mirror
  124. .fi
  125. .RE
  126. .P
  127. If you need to pass arguments to a script command, use \fB--\fR to separate npm arguments from script arguments:
  128. .P
  129. .RS 2
  130. .nf
  131. npm run build -- --customFlag
  132. .fi
  133. .RE
  134. .P
  135. Using environment variables is also recommended for cross-platform configuration instead of defining unsupported keys in \fB.npmrc\fR.
  136. .P
  137. .RS 2
  138. .nf
  139. ; bad config
  140. _authToken=MYTOKEN
  141. ; good config
  142. @myorg:registry=https://somewhere-else.com/myorg
  143. @another:registry=https://somewhere-else.com/another
  144. //registry.npmjs.org/:_authToken=MYTOKEN
  145. ; would apply to both @myorg and @another
  146. //somewhere-else.com/:_authToken=MYTOKEN
  147. ; would apply only to @myorg
  148. //somewhere-else.com/myorg/:_authToken=MYTOKEN1
  149. ; would apply only to @another
  150. //somewhere-else.com/another/:_authToken=MYTOKEN2
  151. .fi
  152. .RE
  153. .SS "Custom / third-party config keys"
  154. .P
  155. npm only recognizes its own npm help "configuration options". If your \fB.npmrc\fR contains keys that are not part of npm's config definitions (for example, \fBelectron_mirror\fR or \fBsass_binary_site\fR), npm will emit a warning:
  156. .P
  157. .RS 2
  158. .nf
  159. warn Unknown user config "electron_mirror".
  160. This will stop working in the next major version of npm.
  161. .fi
  162. .RE
  163. .P
  164. These keys were historically tolerated but are not officially supported. A future major version of npm will treat unknown top-level keys as errors.
  165. .P
  166. Some tools (such as \fB@electron/get\fR or \fBnode-sass\fR) read their own configuration from environment variables or from \fB.npmrc\fR by convention. You can set these values as environment variables instead:
  167. .P
  168. .RS 2
  169. .nf
  170. export ELECTRON_MIRROR="https://mirrorexample.npmjs.org/mirrors/electron/"
  171. export ELECTRON_CUSTOM_DIR="{{ version }}"
  172. .fi
  173. .RE
  174. .P
  175. Environment variables are the most portable approach and work regardless of \fB.npmrc\fR format.
  176. .SS "See also"
  177. .RS 0
  178. .IP \(bu 4
  179. npm help folders
  180. .IP \(bu 4
  181. npm help config
  182. .IP \(bu 4
  183. npm help config
  184. .IP \(bu 4
  185. \fBpackage.json\fR \fI\(la/configuring-npm/package-json\(ra\fR
  186. .IP \(bu 4
  187. npm help npm
  188. .RE 0