what is the .npmrc
the. npmrc file is the npm running configuration file. In this file, we can config that where we can load the source what we need;point the version of the source and where the source is located.
where the file is located
- You can place the file in your current project’s root package. If that the file only controls the project.
- You can place the file in your home directory(where is your home directory). If that, the file will affect all of the projects which are created by the current account.you can get the positon by ‘npm config get userconfig’.
- you can place it at ‘$PREFIX/etc/npmrc‘,the file will controls all of the project which is created by the user who use the conputer.you can get the position by .
- Finally, it can be placed at the npm built in, but we usually do not use it.
how to config it
create a file called ‘. npmrc’ and set some config using the form ‘key = value’,for example:
//change the origin of the downloadregistry=https://registry.npm.taobao.org
If you want to delete some config, you just delete the code which you want to delete.
use command line, you can use ‘npm config set‘ to set them.for example:
npm config set registry https://registry.npm.taobao.org
upon has the same effect as the first handle.It will change the file which is placed at home directory.you can use ‘npm config delete ‘ to delete some config. for example:
npm config delete registry
if you want to change the file which is placed at the ‘$PREFIX/etc/npmrc‘,You can use the command which is the same as the upon command which is used in the second paragraph, but we need concat ‘-g’ or ‘—global’ at the end of the command.for example:
npm config set registry https://registry.npm.taobao.org -g
some frequently-used command
npm config set <key> <value> [-g|--global] //给配置参数key设置值为value;npm config get <key> //获取配置参数key的值;npm config delete <key> //删除置参数key及其值;npm config list [-l] //显示npm的所有配置参数的信息;npm config edit //编辑配置文件npm get <key> //获取配置参数key的值;npm set <key> <value> [-g|--global] //给配置参数key设置值为value;
