npm yarn node 常用命令 - fubd/blowfish GitHub Wiki

命令

// 查看全局安装的包
npm ls -g --depth=0 

// 安装express
npm install -g express-generator
express --view=ejs myapp

// 缩写
npm --save => npm -S
npm --save-dev => npm -D

// 查看包版本
npm view [PACKAGE] // 只能查看最新版本,维护者,和publish时间
npm view [PACKAGE] versions  // 查看包所有版本
npm ls [PACKAGE]   // 查看当前包版本



镜像

npm config set registry https://registry.npm.taobao.org    设置淘宝源

npm config get registry 查看正使用源

npm config delete registry 
npm config delete disturl   重置 npm源

// 使用nrm管理npm源
npm i -g j nrm
nrm ls
nrm use <name>

版本

// 安装
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source $HOME/.nvm/nvm.sh

// 若重启后提示 node command not found
nvm alias default node

// 列出所有的node版本
nvm ls-remote 

// 指定默认版本的node
nvm alias default 0.10.32 

// 卸载nvm
rm -rf $NVM_DIR ~/.npm ~/.bower 卸载nvm

// 若mac重启后nvm找不到
touch .bash_profile //新建文件

open .bash_profile //打开文件
添加
export NVM_DIR="$HOME/.nvm"  
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

问题

npm i安装时卡到 提示 node-pre-gyp WARN Using request for node-pre-gyp https download
npm --build-from-source install
参考 https://www.axihe.com/anbang/blog/npm/build-from-source.html

⚠️ **GitHub.com Fallback** ⚠️