Nodejs_npm_yarn
安装node.js
(archlinux发行版及其衍生版上,其他版本可用相关的软件包管理工具进行安装,如:yum apt-get,也可到官网下载安装包进行安装)
sudo pacman -S nodejs
#项目出现TypeError [ERR_INVALID_ARG_TYPE]错误时降级安装nodejs-lts-erbium node12长期支持版
node -v
用yarn替换npm命令
npm (v5) | Yarn |
---|---|
npm install [package] --save |
yarn add [package] |
npm install [package] --save-dev |
yarn add [package] --dev |
(N/A) | yarn add [package] --peer |
npm install [package] --save-optional |
yarn add [package] --optional |
npm install [package] --save-exact |
yarn add [package] --exact |
(N/A) | yarn add [package] --tilde |
npm install [package] --global |
yarn global add [package] |
npm update --global |
yarn global upgrade |
npm rebuild |
yarn add --force |
npm uninstall [package] |
yarn remove [package] |
npm cache clean |
yarn cache clean [package] |
rm -rf node_modules && npm install |
yarn upgrade |
npm version major |
yarn version --major |
npm version minor |
yarn version --minor |
npm version patch |
yarn version --patch |
镜像源配置
简单修改
yarn
# 临时修改(只生效一次)
yarn save 包的名字 --registry https://registry.npm.taobao.org
# 设置npm的配置项(全局配置)
yarn config set registry https://registry.npm.taobao.org
# 查看npm源的当前地址
yarn config get registry
npm
# 临时修改(只生效一次)
npm install 包的名字 --registry https://registry.npm.taobao.org
# 设置npm的配置项(全局配置)
npm config set registry https://registry.npm.taobao.org
# 查看npm源的当前地址
npm config get registry
使用工具修改
yarn
# 安装工具
sudo yarn global add yrm
# 列出可选源
yrm ls
* npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
# 测试源响应时间
yrm test
* npm ---- 13480ms
cnpm --- 1807ms
taobao - 482ms
nj ----- Fetch Error
rednpm - Fetch Error
npmMirror 2499ms
edunpm - Fetch Error
yarn --- Fetch Error
# 切换源
yrm use taobao
npm
# 安装工具
npm install -g nrm
# 列出可选源
nrm ls
* npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http://registry.enpmjs.org/
# 测试源响应时间
nrm test
* npm ---- 1440ms
cnpm --- 937ms
taobao - 392ms
nj ----- Fetch Error
rednpm - Fetch Error
npmMirror 1296ms
edunpm - Fetch Error
# 切换源
nrm use taobao