deprecate-totp-2fa
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npmrc |
| 3 | section: 5 |
| 4 | description: The npm config files |
| 5 | github_repo: npm/cli |
| 6 | github_branch: latest |
| 7 | github_path: docs/lib/content/configuring-npm/npmrc.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/configuring-npm/npmrc |
| 10 | - /cli-documentation/files/npmrc |
| 11 | - /cli-documentation/v11/configuring-npm/npmrc |
| 12 | - /cli-documentation/v11/files/npmrc |
| 13 | - /cli/configuring-npm/npmrc |
| 14 | - /cli/files/npmrc |
| 15 | - /cli/v11/files/npmrc |
| 16 | - /configuring-npm/npmrc |
| 17 | - /files/npmrc |
| 18 | --- |
| 19 | |
| 20 | ### Description |
| 21 | |
| 22 | npm gets its config settings from the command line, environment variables, and `npmrc` files. |
| 23 | |
| 24 | The `npm config` command can be used to update and edit the contents of the user and global npmrc files. |
| 25 | |
| 26 | For a list of available configuration options, see [config](/cli/v11/using-npm/config). |
| 27 | |
| 28 | ### Files |
| 29 | |
| 30 | The four relevant files are: |
| 31 | |
| 32 | - per-project config file (`/path/to/my/project/.npmrc`) |
| 33 | - per-user config file (`~/.npmrc`) |
| 34 | - global config file (`$PREFIX/etc/npmrc`) |
| 35 | - npm builtin config file (`/path/to/npm/npmrc`) |
| 36 | |
| 37 | All npm config files are an ini-formatted list of `key = value` parameters. Environment variables can be replaced using `${VARIABLE_NAME}`. By default if the variable is not defined, it is left unreplaced. By adding `?` after variable name they can be forced to evaluate to an empty string instead. For example: |
| 38 | |
| 39 | ```bash |
| 40 | cache = ${HOME}/.npm-packages |
| 41 | node-options = "${NODE_OPTIONS?} --use-system-ca" |
| 42 | ``` |
| 43 | |
| 44 | 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. |
| 45 | |
| 46 | Array values are specified by adding "[]" after the key name. For example: |
| 47 | |
| 48 | ```bash |
| 49 | key[] = "first value" |
| 50 | key[] = "second value" |
| 51 | ``` |
| 52 | |
| 53 | #### Comments |
| 54 | |
| 55 | Lines in `.npmrc` files are interpreted as comments when they begin with a `;` or `#` character. `.npmrc` files are parsed by [npm/ini](https://github.com/npm/ini), which specifies this comment syntax. |
| 56 | |
| 57 | For example: |
| 58 | |
| 59 | ```bash |
| 60 | # last modified: 01 Jan 2016 |
| 61 | ; Set a new registry for a scoped package |
| 62 | @myscope:registry=https://mycustomregistry.example.org |
| 63 | ``` |
| 64 | |
| 65 | #### Per-project config file |
| 66 | |
| 67 | When working locally in a project, a `.npmrc` file in the root of the project (ie, a sibling of `node_modules` and `package.json`) will set config values specific to this project. |
| 68 | |
| 69 | 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. |
| 70 | |
| 71 | Additionally, this file is not read in global mode, such as when running `npm install -g`. |
| 72 | |
| 73 | #### Per-user config file |
| 74 | |
| 75 | `$HOME/.npmrc` (or the `userconfig` param, if set in the environment or on the command line) |
| 76 | |
| 77 | #### Global config file |
| 78 | |
| 79 | `$PREFIX/etc/npmrc` (or the `globalconfig` param, if set above): This file is an ini-file formatted list of `key = value` parameters. Environment variables can be replaced as above. |
| 80 | |
| 81 | #### Built-in config file |
| 82 | |
| 83 | `path/to/npm/itself/npmrc` |
| 84 | |
| 85 | This is an unchangeable "builtin" configuration file that npm keeps consistent across updates. Set fields in here using the `./configure` script that comes with npm. This is primarily for distribution maintainers to override default configs in a standard and consistent manner. |
| 86 | |
| 87 | ### Auth related configuration |
| 88 | |
| 89 | The settings `_auth`, `_authToken`, `username`, `_password`, `certfile`, and `keyfile` must all be scoped to a specific registry. This ensures that `npm` will never send credentials to the wrong host. |
| 90 | |
| 91 | The full list is: |
| 92 | |
| 93 | - `_auth` (base64 authentication string) |
| 94 | - `_authToken` (authentication token) |
| 95 | - `username` |
| 96 | - `_password` |
| 97 | - `email` |
| 98 | - `cafile` (path to certificate authority file) |
| 99 | - `certfile` (path to certificate file) |
| 100 | - `keyfile` (path to key file) |
| 101 | |
| 102 | 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 `//registry.npmjs.org/:`. If it must be scoped to a specific path on the host that path may also be provided, such as `//my-custom-registry.org/unique/path:`. |
| 103 | |
| 104 | ``` |
| 105 | ; bad config |
| 106 | _authToken=MYTOKEN |
| 107 | |
| 108 | ; good config |
| 109 | @myorg:registry=https://somewhere-else.com/myorg |
| 110 | @another:registry=https://somewhere-else.com/another |
| 111 | //registry.npmjs.org/:_authToken=MYTOKEN |
| 112 | |
| 113 | ; would apply to both @myorg and @another |
| 114 | //somewhere-else.com/:_authToken=MYTOKEN |
| 115 | |
| 116 | ; would apply only to @myorg |
| 117 | //somewhere-else.com/myorg/:_authToken=MYTOKEN1 |
| 118 | |
| 119 | ; would apply only to @another |
| 120 | //somewhere-else.com/another/:_authToken=MYTOKEN2 |
| 121 | ``` |
| 122 | |
| 123 | ### See also |
| 124 | |
| 125 | - [npm folders](/cli/v11/configuring-npm/folders) |
| 126 | - [npm config](/cli/v11/commands/npm-config) |
| 127 | - [config](/cli/v11/using-npm/config) |
| 128 | - [package.json](/cli/v11/configuring-npm/package-json) |
| 129 | - [npm](/cli/v11/commands/npm) |