11cb0ef41Sopenharmony_ci--- 21cb0ef41Sopenharmony_cititle: npmrc 31cb0ef41Sopenharmony_cisection: 5 41cb0ef41Sopenharmony_cidescription: The npm config files 51cb0ef41Sopenharmony_ci--- 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci### Description 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cinpm gets its config settings from the command line, environment variables, 101cb0ef41Sopenharmony_ciand `npmrc` files. 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciThe `npm config` command can be used to update and edit the contents of the 131cb0ef41Sopenharmony_ciuser and global npmrc files. 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciFor a list of available configuration options, see 161cb0ef41Sopenharmony_ci[config](/using-npm/config). 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci### Files 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciThe four relevant files are: 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci* per-project config file (`/path/to/my/project/.npmrc`) 231cb0ef41Sopenharmony_ci* per-user config file (`~/.npmrc`) 241cb0ef41Sopenharmony_ci* global config file (`$PREFIX/etc/npmrc`) 251cb0ef41Sopenharmony_ci* npm builtin config file (`/path/to/npm/npmrc`) 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciAll npm config files are an ini-formatted list of `key = value` parameters. 281cb0ef41Sopenharmony_ciEnvironment variables can be replaced using `${VARIABLE_NAME}`. For 291cb0ef41Sopenharmony_ciexample: 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci```bash 321cb0ef41Sopenharmony_ciprefix = ${HOME}/.npm-packages 331cb0ef41Sopenharmony_ci``` 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciEach of these files is loaded, and config options are resolved in priority 361cb0ef41Sopenharmony_ciorder. For example, a setting in the userconfig file would override the 371cb0ef41Sopenharmony_cisetting in the globalconfig file. 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciArray values are specified by adding "[]" after the key name. For example: 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci```bash 421cb0ef41Sopenharmony_cikey[] = "first value" 431cb0ef41Sopenharmony_cikey[] = "second value" 441cb0ef41Sopenharmony_ci``` 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci#### Comments 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciLines in `.npmrc` files are interpreted as comments when they begin with a 491cb0ef41Sopenharmony_ci`;` or `#` character. `.npmrc` files are parsed by 501cb0ef41Sopenharmony_ci[npm/ini](https://github.com/npm/ini), which specifies this comment syntax. 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciFor example: 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci```bash 551cb0ef41Sopenharmony_ci# last modified: 01 Jan 2016 561cb0ef41Sopenharmony_ci; Set a new registry for a scoped package 571cb0ef41Sopenharmony_ci@myscope:registry=https://mycustomregistry.example.org 581cb0ef41Sopenharmony_ci``` 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ci#### Per-project config file 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciWhen working locally in a project, a `.npmrc` file in the root of the 631cb0ef41Sopenharmony_ciproject (ie, a sibling of `node_modules` and `package.json`) will set 641cb0ef41Sopenharmony_ciconfig values specific to this project. 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ciNote that this only applies to the root of the project that you're running 671cb0ef41Sopenharmony_cinpm in. It has no effect when your module is published. For example, you 681cb0ef41Sopenharmony_cican't publish a module that forces itself to install globally, or in a 691cb0ef41Sopenharmony_cidifferent location. 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ciAdditionally, this file is not read in global mode, such as when running 721cb0ef41Sopenharmony_ci`npm install -g`. 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci#### Per-user config file 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci`$HOME/.npmrc` (or the `userconfig` param, if set in the environment or on 771cb0ef41Sopenharmony_cithe command line) 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci#### Global config file 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci`$PREFIX/etc/npmrc` (or the `globalconfig` param, if set above): This file 821cb0ef41Sopenharmony_ciis an ini-file formatted list of `key = value` parameters. Environment 831cb0ef41Sopenharmony_civariables can be replaced as above. 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci#### Built-in config file 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci`path/to/npm/itself/npmrc` 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciThis is an unchangeable "builtin" configuration file that npm keeps 901cb0ef41Sopenharmony_ciconsistent across updates. Set fields in here using the `./configure` 911cb0ef41Sopenharmony_ciscript that comes with npm. This is primarily for distribution maintainers 921cb0ef41Sopenharmony_cito override default configs in a standard and consistent manner. 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ci### Auth related configuration 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ciThe settings `_auth`, `_authToken`, `username` and `_password` must all be 971cb0ef41Sopenharmony_ciscoped to a specific registry. This ensures that `npm` will never send 981cb0ef41Sopenharmony_cicredentials to the wrong host. 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ciThe full list is: 1011cb0ef41Sopenharmony_ci - `_auth` (base64 authentication string) 1021cb0ef41Sopenharmony_ci - `_authToken` (authentication token) 1031cb0ef41Sopenharmony_ci - `username` 1041cb0ef41Sopenharmony_ci - `_password` 1051cb0ef41Sopenharmony_ci - `email` 1061cb0ef41Sopenharmony_ci - `certfile` (path to certificate file) 1071cb0ef41Sopenharmony_ci - `keyfile` (path to key file) 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciIn order to scope these values, they must be prefixed by a URI fragment. 1101cb0ef41Sopenharmony_ciIf the credential is meant for any request to a registry on a single host, 1111cb0ef41Sopenharmony_cithe scope may look like `//registry.npmjs.org/:`. If it must be scoped to a 1121cb0ef41Sopenharmony_cispecific path on the host that path may also be provided, such as 1131cb0ef41Sopenharmony_ci`//my-custom-registry.org/unique/path:`. 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci``` 1161cb0ef41Sopenharmony_ci; bad config 1171cb0ef41Sopenharmony_ci_authToken=MYTOKEN 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_ci; good config 1201cb0ef41Sopenharmony_ci@myorg:registry=https://somewhere-else.com/myorg 1211cb0ef41Sopenharmony_ci@another:registry=https://somewhere-else.com/another 1221cb0ef41Sopenharmony_ci//registry.npmjs.org/:_authToken=MYTOKEN 1231cb0ef41Sopenharmony_ci; would apply to both @myorg and @another 1241cb0ef41Sopenharmony_ci; //somewhere-else.com/:_authToken=MYTOKEN 1251cb0ef41Sopenharmony_ci; would apply only to @myorg 1261cb0ef41Sopenharmony_ci//somewhere-else.com/myorg/:_authToken=MYTOKEN1 1271cb0ef41Sopenharmony_ci; would apply only to @another 1281cb0ef41Sopenharmony_ci//somewhere-else.com/another/:_authToken=MYTOKEN2 1291cb0ef41Sopenharmony_ci``` 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci### See also 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci* [npm folders](/configuring-npm/folders) 1341cb0ef41Sopenharmony_ci* [npm config](/commands/npm-config) 1351cb0ef41Sopenharmony_ci* [config](/using-npm/config) 1361cb0ef41Sopenharmony_ci* [package.json](/configuring-npm/package-json) 1371cb0ef41Sopenharmony_ci* [npm](/commands/npm) 138